<!DOCTYPE html>












  


<html class="theme-next mist use-motion" lang="zh-CN">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">


























<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2">

<link rel="stylesheet" href="/css/main.css?v=7.0.0">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=7.0.0">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.ico?v=7.0.0">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.ico?v=7.0.0">


  <link rel="mask-icon" href="/images/logo.svg?v=7.0.0" color="#222">







<script id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Mist',
    version: '7.0.0',
    sidebar: {"position":"left","display":"hide","offset":12,"b2t":false,"scrollpercent":true,"onmobile":false},
    fancybox: false,
    fastclick: false,
    lazyload: false,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>


  




  <meta name="description" content="注：本文出自博主 Chloneda：个人博客 | 博客园 | Github | Gitee | 知乎 Vim命令速查表 个人Vim命令速查表。  vim-cheatsheet | Vim官网 | Github | Vim中文文档  Vim自定义配置文件 - vimrc Chrome浏览器神级插件 - Vimium  光标移动注：一般模式下，任意一个动作都可以重复。 1234567891011121">
<meta name="keywords" content="Vim">
<meta property="og:type" content="article">
<meta property="og:title" content="Vim命令速查表">
<meta property="og:url" content="https://chloneda.github.io/blog/vim-cheatsheet/index.html">
<meta property="og:site_name" content="Chloneda">
<meta property="og:description" content="注：本文出自博主 Chloneda：个人博客 | 博客园 | Github | Gitee | 知乎 Vim命令速查表 个人Vim命令速查表。  vim-cheatsheet | Vim官网 | Github | Vim中文文档  Vim自定义配置文件 - vimrc Chrome浏览器神级插件 - Vimium  光标移动注：一般模式下，任意一个动作都可以重复。 1234567891011121">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="https://chloneda.github.io/uploads/vim.png">
<meta property="og:updated_time" content="2020-03-30T14:33:48.120Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Vim命令速查表">
<meta name="twitter:description" content="注：本文出自博主 Chloneda：个人博客 | 博客园 | Github | Gitee | 知乎 Vim命令速查表 个人Vim命令速查表。  vim-cheatsheet | Vim官网 | Github | Vim中文文档  Vim自定义配置文件 - vimrc Chrome浏览器神级插件 - Vimium  光标移动注：一般模式下，任意一个动作都可以重复。 1234567891011121">
<meta name="twitter:image" content="https://chloneda.github.io/uploads/vim.png">



  <link rel="alternate" href="/rss2.html" title="Chloneda" type="application/atom+xml">




  <link rel="canonical" href="https://chloneda.github.io/blog/vim-cheatsheet/">



<script id="page.configurations">
  CONFIG.page = {
    sidebar: "",
  };
</script>

  <title>Vim命令速查表 | Chloneda</title>
  












  <noscript>
  <style>
  .use-motion .motion-element,
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-title { opacity: initial; }

  .use-motion .logo,
  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-CN">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Chloneda</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
    
      
        <h1 class="site-subtitle" itemprop="description">简约的程序员</h1>
      
    
    
  </div>

  <div class="site-nav-toggle">
    <button aria-label="切换导航栏">
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>



<nav class="site-nav">
  
    <ul id="menu" class="menu">
      
        
        
        
          
          <li class="menu-item menu-item-home">

    
    
    
      
    

    

    <a href="/" rel="section"><i class="menu-item-icon fa fa-fw fa-home"></i> <br>首页</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-archives">

    
    
    
      
    

    

    <a href="/archives/" rel="section"><i class="menu-item-icon fa fa-fw fa-archive"></i> <br>归档</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-categories">

    
    
    
      
    

    

    <a href="/categories/" rel="section"><i class="menu-item-icon fa fa-fw fa-th"></i> <br>分类</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-tags">

    
    
    
      
    

    

    <a href="/tags/" rel="section"><i class="menu-item-icon fa fa-fw fa-tags"></i> <br>标签</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-project">

    
    
    
      
    

    

    <a href="/project/" rel="section"><i class="menu-item-icon fa fa-fw fa-github"></i> <br>项目</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-about">

    
    
    
      
    

    

    <a href="/about/" rel="section"><i class="menu-item-icon fa fa-fw fa-user"></i> <br>关于</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-links">

    
    
    
      
    

    

    <a href="/links/" rel="section"><i class="menu-item-icon fa fa-fw fa-link"></i> <br>友链</a>

  </li>

      
      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br>搜索</a>
        </li>
      
    </ul>
  

  
    

  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off" placeholder="搜索..." spellcheck="false" type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



  



</div>
    </header>

    


    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://chloneda.github.io/blog/vim-cheatsheet/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="chloneda">
      <meta itemprop="description" content="Less is more">
      <meta itemprop="image" content="/images/chloneda.jpeg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Chloneda">
    </span>

    
      <header class="post-header">

        
        
          <h2 class="post-title" itemprop="name headline">Vim命令速查表

              
            
          </h2>
        

        <div class="post-meta">
          <span class="post-time">

            
            
            

            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              

              
                
              

              <time title="创建时间：2020-03-30 22:33:48" itemprop="dateCreated datePublished" datetime="2020-03-30T22:33:48+08:00">2020-03-30</time>
            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/categories/Vim/" itemprop="url" rel="index"><span itemprop="name">Vim</span></a></span>

                
                
              
            </span>
          

          

          
          

          
            <span class="post-meta-divider">|</span>
            <span class="post-meta-item-icon">
            <i class="fa fa-eye"></i>
             阅读次数： 
            <span class="busuanzi-value" id="busuanzi_value_page_pv"></span>
            </span>
          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p><strong>注：本文出自博主 Chloneda</strong>：<a href="https://chloneda.github.io/">个人博客</a> | <a href="https://www.cnblogs.com/chloneda" target="_blank" rel="noopener">博客园</a> | <a href="https://github.com/chloneda" target="_blank" rel="noopener">Github</a> | <a href="https://gitee.com/chloneda" target="_blank" rel="noopener">Gitee</a> | <a href="https://www.zhihu.com/people/chl_vip/" target="_blank" rel="noopener">知乎</a></p>
<h1 id="Vim命令速查表"><a href="#Vim命令速查表" class="headerlink" title="Vim命令速查表"></a>Vim命令速查表</h1><blockquote>
<p>个人Vim命令速查表。</p>
</blockquote>
<p><a href="https://github.com/chloneda/vim-cheatsheet" target="_blank" rel="noopener">vim-cheatsheet</a> | <a href="https://www.vim.org/" target="_blank" rel="noopener">Vim官网</a> | <a href="https://github.com/vim/vim" target="_blank" rel="noopener">Github</a> | <a href="http://vimcdoc.sourceforge.net/doc/help.html" target="_blank" rel="noopener">Vim中文文档</a></p>
<ul>
<li><a href="https://github.com/chloneda/vim-cheatsheet/blob/master/vimrc" target="_blank" rel="noopener">Vim自定义配置文件 - vimrc</a></li>
<li><a href="https://github.com/chloneda/vim-cheatsheet/blob/master/vimium.md" target="_blank" rel="noopener">Chrome浏览器神级插件 - Vimium</a></li>
</ul>
<h2 id="光标移动"><a href="#光标移动" class="headerlink" title="光标移动"></a>光标移动</h2><p><strong>注：一般模式下，任意一个动作都可以重复。</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br></pre></td><td class="code"><pre><span class="line">h                   <span class="comment"># 光标左移，同 &lt;Left&gt; 键</span></span><br><span class="line">j                   <span class="comment"># 光标下移，同 &lt;Down&gt; 键</span></span><br><span class="line">k                   <span class="comment"># 光标上移，同 &lt;Up&gt; 键</span></span><br><span class="line">l                   <span class="comment"># 光标右移，同 &lt;Right&gt; 键</span></span><br><span class="line">Ctrl+e              <span class="comment"># 向上滚动一行</span></span><br><span class="line">Ctrl+y              <span class="comment"># 向下滚动一行</span></span><br><span class="line">Ctrl+u              <span class="comment"># 向上滚动半屏 --&gt; move up 1/2 a screen</span></span><br><span class="line">Ctrl+d              <span class="comment"># 向下滚动半屏 --&gt; move down 1/2 a screen</span></span><br><span class="line">Ctrl+f              <span class="comment"># 向下滚动一屏 --&gt; move forward one full screen</span></span><br><span class="line">Ctrl+b              <span class="comment"># 向上滚动一屏 --&gt; move back one full screen</span></span><br><span class="line">0                   <span class="comment"># 跳到行首（是数字零，不是字母O），效用等同于 &lt;Home&gt; 键</span></span><br><span class="line">^                   <span class="comment"># 跳到从行首开始第一个非空白字符</span></span><br><span class="line">$                   <span class="comment"># 跳到行尾，效用等同于 &lt;End&gt; 键</span></span><br><span class="line">gg                  <span class="comment"># 跳到第一行，效用等同于 Ctrl+&lt;Home&gt;</span></span><br><span class="line">G                   <span class="comment"># 跳到最后一行，效用等同于 Ctrl+&lt;End&gt;</span></span><br><span class="line">nG                  <span class="comment"># 跳到第n行，比如 10G 是移动到第十行</span></span><br><span class="line">:n                  <span class="comment"># 跳到第n行，比如 :10&lt;回车&gt; 是移动到第十行</span></span><br><span class="line">10%                 <span class="comment"># 移动到文件 10% 处</span></span><br><span class="line">15|                 <span class="comment"># 移动到当前行的 15列</span></span><br><span class="line">w                   <span class="comment"># 跳到下一个单词开头 (word: 标点或空格分隔的单词)</span></span><br><span class="line">W                   <span class="comment"># 跳到下一个单词开头 (WORD: 空格分隔的单词)</span></span><br><span class="line">e                   <span class="comment"># 跳到下一个单词尾部 (word: 标点或空格分隔的单词)</span></span><br><span class="line">E                   <span class="comment"># 跳到下一个单词尾部 (WORD: 空格分隔的单词)</span></span><br><span class="line">b                   <span class="comment"># 跳到上一个单词开头 (word: 标点或空格分隔的单词)</span></span><br><span class="line">B                   <span class="comment"># 跳到上一个单词开头 (WORD: 空格分隔的单词)</span></span><br><span class="line">ge                  <span class="comment"># 跳到前一个单词结尾</span></span><br><span class="line">)                   <span class="comment"># 向前移动一个句子（句号分隔）</span></span><br><span class="line">(                   <span class="comment"># 向后移动一个句子（句号分隔）</span></span><br><span class="line">&#125;                   <span class="comment"># 向前移动一个段落（空行分隔）</span></span><br><span class="line">&#123;                   <span class="comment"># 向后移动一个段落（空行分隔）</span></span><br><span class="line">&lt;enter&gt;             <span class="comment"># 移动到下一行首个非空字符</span></span><br><span class="line">n&lt;enter&gt;            <span class="comment"># 光标向下移动 n 行</span></span><br><span class="line">+                   <span class="comment"># 移动到下一行首个非空字符（同回车键）</span></span><br><span class="line">-                   <span class="comment"># 移动到上一行首个非空字符</span></span><br><span class="line">H                   <span class="comment"># 移动到屏幕上部</span></span><br><span class="line">M                   <span class="comment"># 移动到屏幕中部</span></span><br><span class="line">L                   <span class="comment"># 移动到屏幕下部</span></span><br><span class="line">&lt;S+Left&gt;            <span class="comment"># 按住 SHIFT 按左键，向左移动一个单词</span></span><br><span class="line">&lt;S+Right&gt;           <span class="comment"># 按住 SHIFT 按右键，向右移动一个单词</span></span><br><span class="line">&lt;S+Up&gt;              <span class="comment"># 按住 SHIFT 按上键，向上翻页</span></span><br><span class="line">&lt;S+Down&gt;            <span class="comment"># 按住 SHIFT 按下键，向下翻页</span></span><br><span class="line">gm                  <span class="comment"># 移动到行中</span></span><br><span class="line">gj                  <span class="comment"># 光标向下移动一个屏幕行（忽略自动换行）</span></span><br><span class="line">gk                  <span class="comment"># 光标向上移动一个屏幕行（忽略自动换行）</span></span><br><span class="line">zz                  <span class="comment"># 调整光标所在行到屏幕中央</span></span><br><span class="line">zt                  <span class="comment"># 调整光标所在行到屏幕上部</span></span><br><span class="line">zb                  <span class="comment"># 调整光标所在行到屏幕下部</span></span><br></pre></td></tr></table></figure>
<h2 id="插入模式"><a href="#插入模式" class="headerlink" title="插入模式"></a>插入模式</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">i                   <span class="comment"># 在光标处进入插入模式</span></span><br><span class="line">I                   <span class="comment"># 在行首进入插入模式</span></span><br><span class="line">a                   <span class="comment"># 在光标后进入插入模式</span></span><br><span class="line">A                   <span class="comment"># 在行尾进入插入模式</span></span><br><span class="line">o                   <span class="comment"># 在下一行插入新行并进入插入模式</span></span><br><span class="line">O                   <span class="comment"># 在上一行插入新行并进入插入模式</span></span><br><span class="line">gi                  <span class="comment"># 进入到上一次插入模式的位置</span></span><br><span class="line">&lt;esc&gt;               <span class="comment"># 退出插入模式</span></span><br><span class="line">Ctrl+[              <span class="comment"># 退出插入模式（等价于 esc 键）</span></span><br></pre></td></tr></table></figure>
<h2 id="插入模式的命令"><a href="#插入模式的命令" class="headerlink" title="插入模式的命令"></a>插入模式的命令</h2><p><strong>注：由 i, I, a, A, o, O 等命令进入插入模式</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><span class="line">&lt;Up&gt;                <span class="comment"># 光标向上移动</span></span><br><span class="line">&lt;Down&gt;              <span class="comment"># 光标向下移动</span></span><br><span class="line">&lt;Left&gt;              <span class="comment"># 光标向左移动</span></span><br><span class="line">&lt;Right&gt;             <span class="comment"># 光标向右移动</span></span><br><span class="line">&lt;S+Left&gt;            <span class="comment"># 按住 SHIFT 按左键，向左移动一个单词</span></span><br><span class="line">&lt;S+Right&gt;           <span class="comment"># 按住 SHIFT 按右键，向右移动一个单词</span></span><br><span class="line">&lt;S+Up&gt;              <span class="comment"># 按住 SHIFT 按上键，向上翻页</span></span><br><span class="line">&lt;S+Down&gt;            <span class="comment"># 按住 SHIFT 按下键，向下翻页</span></span><br><span class="line">&lt;PageUp&gt;            <span class="comment"># 上翻页</span></span><br><span class="line">&lt;PageDown&gt;          <span class="comment"># 下翻页</span></span><br><span class="line">&lt;Delete&gt;            <span class="comment"># 删除光标处字符</span></span><br><span class="line">&lt;BS&gt;                <span class="comment"># Backspace 向后删除字符</span></span><br><span class="line">&lt;Home&gt;              <span class="comment"># 光标跳转行首</span></span><br><span class="line">&lt;End&gt;               <span class="comment"># 光标跳转行尾</span></span><br><span class="line">Ctrl+d              <span class="comment"># 减少缩进</span></span><br><span class="line">Ctrl+f              <span class="comment"># 减少缩进</span></span><br><span class="line">Ctrl+t              <span class="comment"># 增加缩进</span></span><br><span class="line">Ctrl+h              <span class="comment"># 删除前一个字符，相当于回格键backspace</span></span><br><span class="line">Ctrl+o              <span class="comment"># 临时退出插入模式，执行单条命令又返回插入模式</span></span><br><span class="line">Ctrl+u              <span class="comment"># 当前行删除到行首所有字符</span></span><br><span class="line">Ctrl+w              <span class="comment"># 删除光标前的一个单词</span></span><br><span class="line">Ctrl+\ Ctrl+O       <span class="comment"># 临时退出插入模式（光标保持），执行单条命令又返回插入模式</span></span><br><span class="line">Ctrl+R 0            <span class="comment"># 插入寄存器（内部 0号剪贴板）内容，Ctrl+R 后可跟寄存器名</span></span><br><span class="line">Ctrl+R <span class="string">"            # 插入匿名寄存器内容，相当于插入模式下 p粘贴</span></span><br><span class="line"><span class="string">Ctrl+R =            # 插入表达式计算结果，等号后面跟表达式</span></span><br><span class="line"><span class="string">Ctrl+R :            # 插入上一次命令行命令</span></span><br><span class="line"><span class="string">Ctrl+R /            # 插入上一次搜索的关键字</span></span><br><span class="line"><span class="string">Ctrl+v &#123;char&#125;       # 插入非数字的字面量</span></span><br><span class="line"><span class="string">Ctrl+v &#123;code&#125;       # 插入用三位数字表示的ascii/unicode字符编码，如Ctrl+v 065</span></span><br><span class="line"><span class="string">Ctrl+v 065          # 插入 10进制 ascii 字符（两数字） 065 即 A字符</span></span><br><span class="line"><span class="string">Ctrl+v x41          # 插入 16进制 ascii 字符（三数字） x41 即 A字符</span></span><br><span class="line"><span class="string">Ctrl+v o101         # 插入  8进制 ascii 字符（三数字） o101 即 A字符</span></span><br><span class="line"><span class="string">Ctrl+v u1234        # 插入 16进制 unicode 字符（四数字）</span></span><br><span class="line"><span class="string">Ctrl+v U12345678    # 插入 16进制 unicode 字符（八数字）</span></span><br><span class="line"><span class="string">Ctrl+K &#123;ch1&#125; &#123;ch2&#125;  # 插入 digraph（见 :h digraph），快速输入日文或符号等</span></span><br></pre></td></tr></table></figure>
<h2 id="自动补全"><a href="#自动补全" class="headerlink" title="自动补全"></a>自动补全</h2><p>在插入模式下，最常用的补全</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">Ctrl+n              <span class="comment"># 插入模式下文字自动补全 </span></span><br><span class="line">Ctrl+P              <span class="comment"># 插入模式下文字自动补全</span></span><br><span class="line">Ctrl+e              <span class="comment"># 有补全列表时，终止这次补全，继续输入</span></span><br></pre></td></tr></table></figure>
<p><strong>智能补全</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">Ctrl+X              <span class="comment"># 进入补全模式</span></span><br><span class="line">Ctrl+X Ctrl+L       <span class="comment"># 整行补全</span></span><br><span class="line">Ctrl+X Ctrl+N       <span class="comment"># 插入模式下，根据当前文件里关键字补全</span></span><br><span class="line">Ctrl+X Ctrl+K       <span class="comment"># 根据字典补全</span></span><br><span class="line">Ctrl+X Ctrl+T       <span class="comment"># 根据同义词字典补全</span></span><br><span class="line">Ctrl+X Ctrl+F       <span class="comment"># 插入模式下补全文件名</span></span><br><span class="line">Ctrl+X Ctrl+I       <span class="comment"># 根据头文件内关键字补全</span></span><br><span class="line">Ctrl+X Ctrl+]       <span class="comment"># 根据标签补全</span></span><br><span class="line">Ctrl+X Ctrl+D       <span class="comment"># 补全宏定义</span></span><br><span class="line">Ctrl+X Ctrl+V       <span class="comment"># 补全vim命令</span></span><br><span class="line">Ctrl+X Ctrl+U       <span class="comment"># 用户自定义补全方式</span></span><br><span class="line">Ctrl+X Ctrl+S       <span class="comment"># 拼写建议，例如：一个英文单词</span></span><br><span class="line">Ctrl+X Ctrl+O       <span class="comment"># 插入下 Omnifunc 补全</span></span><br></pre></td></tr></table></figure>
<h2 id="文本编辑"><a href="#文本编辑" class="headerlink" title="文本编辑"></a>文本编辑</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br></pre></td><td class="code"><pre><span class="line">r                   <span class="comment"># 替换当前字符</span></span><br><span class="line">R                   <span class="comment"># 进入替换模式，直至 ESC 离开</span></span><br><span class="line">s                   <span class="comment"># 替换字符（删除光标处字符，并进入插入模式，前可接数量）</span></span><br><span class="line">S                   <span class="comment"># 替换行（删除当前行，并进入插入模式，前可接数量）</span></span><br><span class="line">cc                  <span class="comment"># 改写当前行（删除当前行并进入插入模式），同 S</span></span><br><span class="line">cw                  <span class="comment"># 改写光标开始处的当前单词</span></span><br><span class="line">ciw                 <span class="comment"># 改写光标所处的单词</span></span><br><span class="line">caw                 <span class="comment"># 改写光标所处的单词，并且包括前后空格（如果有的话）</span></span><br><span class="line">c0                  <span class="comment"># 改写到行首</span></span><br><span class="line">c^                  <span class="comment"># 改写到行首（第一个非零字符）</span></span><br><span class="line">c$                  <span class="comment"># 改写到行末</span></span><br><span class="line">C                   <span class="comment"># 改写到行尾（同c$）</span></span><br><span class="line">ci<span class="string">"                 # 改写双引号中的内容</span></span><br><span class="line"><span class="string">ci'                 # 改写单引号中的内容</span></span><br><span class="line"><span class="string">cib                 # 改写小括号中的内容</span></span><br><span class="line"><span class="string">cab                 # 改写小括号中的内容（包含小括号本身）</span></span><br><span class="line"><span class="string">ci)                 # 改写小括号中的内容</span></span><br><span class="line"><span class="string">ci]                 # 改写中括号中内容</span></span><br><span class="line"><span class="string">ciB                 # 改写大括号中内容</span></span><br><span class="line"><span class="string">caB                 # 改写大括号中的内容（包含大括号本身）</span></span><br><span class="line"><span class="string">ci&#125;                 # 改写大括号中内容</span></span><br><span class="line"><span class="string">cit                 # 改写 xml tag 中的内容</span></span><br><span class="line"><span class="string">cis                 # 改写当前句子</span></span><br><span class="line"><span class="string">c2w                 # 改写下两个单词</span></span><br><span class="line"><span class="string">ct(                 # 改写到小括号前</span></span><br><span class="line"><span class="string">x                   # 删除当前字符，前面可以接数字，3x代表删除三个字符</span></span><br><span class="line"><span class="string">X                   # 向前删除字符</span></span><br><span class="line"><span class="string">dd                  # 删除(剪切)当前行 --&gt; delete (cut) a line </span></span><br><span class="line"><span class="string">d0                  # 删除(剪切)到行首</span></span><br><span class="line"><span class="string">d^                  # 删除(剪切)到行首（第一个非零字符）</span></span><br><span class="line"><span class="string">d$                  # 删除(剪切)到行末</span></span><br><span class="line"><span class="string">D                   # 删除(剪切)到行末（同 d$）</span></span><br><span class="line"><span class="string">dw                  # 删除(剪切)当前单词</span></span><br><span class="line"><span class="string">diw                 # 删除(剪切)光标所处的单词</span></span><br><span class="line"><span class="string">daw                 # 删除(剪切)光标所处的单词，并包含前后空格（如果有的话）</span></span><br><span class="line"><span class="string">di"</span>                 <span class="comment"># 删除双引号中的内容</span></span><br><span class="line">di<span class="string">'                 # 删除单引号中的内容</span></span><br><span class="line"><span class="string">dib                 # 删除小括号中的内容</span></span><br><span class="line"><span class="string">di)                 # 删除小括号中的内容</span></span><br><span class="line"><span class="string">dab                 # 删除小括号内的内容（包含小括号本身）</span></span><br><span class="line"><span class="string">di]                 # 删除中括号中内容</span></span><br><span class="line"><span class="string">diB                 # 删除大括号中内容</span></span><br><span class="line"><span class="string">di&#125;                 # 删除大括号中内容</span></span><br><span class="line"><span class="string">daB                 # 删除大括号内的内容（包含大括号本身）</span></span><br><span class="line"><span class="string">dit                 # 删除 xml tag 中的内容</span></span><br><span class="line"><span class="string">dis                 # 删除当前句子</span></span><br><span class="line"><span class="string">d2w                 # 删除下两个单词</span></span><br><span class="line"><span class="string">dt(                 # 删除到小括号前</span></span><br><span class="line"><span class="string">dgg                 # 删除到文件头部</span></span><br><span class="line"><span class="string">dG                  # 删除到文件尾部</span></span><br><span class="line"><span class="string">d&#125;                  # 删除下一段</span></span><br><span class="line"><span class="string">d&#123;                  # 删除上一段</span></span><br><span class="line"><span class="string">10d                 # 删除当前行开始的10行</span></span><br><span class="line"><span class="string">:10d                # 删除第10行</span></span><br><span class="line"><span class="string">:1,10d              # 删除1-10行</span></span><br><span class="line"><span class="string">J                   # 链接多行为一行</span></span><br><span class="line"><span class="string">.                   # 重复上一次操作</span></span><br><span class="line"><span class="string">~                   # 替换大小写</span></span><br><span class="line"><span class="string">g~iw                # 替换当前单词的大小写</span></span><br><span class="line"><span class="string">gUiw                # 将单词转成大写</span></span><br><span class="line"><span class="string">guiw                # 将当前单词转成小写</span></span><br><span class="line"><span class="string">guu                 # 全行转为小写</span></span><br><span class="line"><span class="string">gUU                 # 全行转为大写</span></span><br><span class="line"><span class="string">&lt;&lt;                  # 减少缩进</span></span><br><span class="line"><span class="string">&gt;&gt;                  # 增加缩进</span></span><br><span class="line"><span class="string">==                  # 自动缩进</span></span><br><span class="line"><span class="string">Ctrl+A              # 增加数字</span></span><br><span class="line"><span class="string">Ctrl+X              # 减少数字</span></span><br></pre></td></tr></table></figure>
<h2 id="复制粘贴"><a href="#复制粘贴" class="headerlink" title="复制粘贴"></a>复制粘贴</h2><p><strong>copy 命令的格式为</strong>：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">:[range]copy&#123;address&#125;</span><br></pre></td></tr></table></figure>
<p><strong>参数说明</strong>：</p>
<ul>
<li>[range] 表示要复制的行范围，其中copy可缩写为 :co 或 :t</li>
<li>{address} 表示复制的目标位置，这两个参数都可以缺省，用于表示Vim光标所在当前行。</li>
</ul>
<p>例如，:5copy. 表示复制Vim当前打开的文件的第 5 行到当前行 (用 . 表示)，即为第 5 行创建一份副本，并放到当前行下方。</p>
<p>下标列出了使用 copy 命令的缩写形式 t 进行文件复制的一些实例及用途，用于理解复制命令 copy 的用途。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">:3,5t.              <span class="comment"># 把第 3 行到第 5 行的内容复制到当前行下方</span></span><br><span class="line">:t5                 <span class="comment"># 把当前行复制到第 5 行下方</span></span><br><span class="line">:t.                 <span class="comment"># 复制当前行到当前行下方 (等价于普通模式下的 yyp)</span></span><br><span class="line">:t$                 <span class="comment"># 把当前行复制到文本结尾</span></span><br><span class="line">:<span class="string">'&lt;,'</span>&gt;t0            <span class="comment"># 把高亮选中的行复制到文件开头</span></span><br></pre></td></tr></table></figure>
<p><strong>常用复制粘贴命令</strong>：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line">p                   <span class="comment"># 粘贴到光标后</span></span><br><span class="line">P                   <span class="comment"># 粘贴到光标前</span></span><br><span class="line">v                   <span class="comment"># 开始标记</span></span><br><span class="line">y                   <span class="comment"># 复制标记内容</span></span><br><span class="line">V                   <span class="comment"># 开始按行标记</span></span><br><span class="line">Ctrl+V              <span class="comment"># 开始列标记</span></span><br><span class="line">y$                  <span class="comment"># 复制当前位置到本行结束的内容</span></span><br><span class="line">yy                  <span class="comment"># 复制当前行 --&gt; yank (copy) a line</span></span><br><span class="line">Y                   <span class="comment"># 复制当前行，同 yy</span></span><br><span class="line">yiw                 <span class="comment"># 复制当前单词</span></span><br><span class="line">3yy                 <span class="comment"># 复制光标下三行内容</span></span><br><span class="line">v0                  <span class="comment"># 选中当前位置到行首</span></span><br><span class="line">v$                  <span class="comment"># 选中当前位置到行末</span></span><br><span class="line">viw                 <span class="comment"># 选中当前单词</span></span><br><span class="line">vib                 <span class="comment"># 选中小括号内的东西</span></span><br><span class="line">vi)                 <span class="comment"># 选中小括号内的东西</span></span><br><span class="line">vi]                 <span class="comment"># 选中中括号内的东西</span></span><br><span class="line">viB                 <span class="comment"># 选中大括号内的东西</span></span><br><span class="line">vi&#125;                 <span class="comment"># 选中大括号内的东西</span></span><br><span class="line">vis                 <span class="comment"># 选中句子中的东西</span></span><br><span class="line">vab                 <span class="comment"># 选中小括号内的东西（包含小括号本身）</span></span><br><span class="line">va)                 <span class="comment"># 选中小括号内的东西（包含小括号本身）</span></span><br><span class="line">va]                 <span class="comment"># 选中中括号内的东西（包含中括号本身）</span></span><br><span class="line">vaB                 <span class="comment"># 选中大括号内的东西（包含大括号本身）</span></span><br><span class="line">va&#125;                 <span class="comment"># 选中大括号内的东西（包含大括号本身）</span></span><br><span class="line">:<span class="built_in">set</span> paste          <span class="comment"># 允许粘贴模式（避免粘贴时自动缩进影响格式）</span></span><br><span class="line">:<span class="built_in">set</span> nopaste        <span class="comment"># 禁止粘贴模式</span></span><br><span class="line"><span class="string">"?yy                # 复制当前行到寄存器 ? ，问号代表 0-9 的寄存器名称</span></span><br><span class="line"><span class="string">"</span>?d3j               <span class="comment"># 删除光标下三行内容，并放到寄存器 ? ，问号代表 0-9 的寄存器名称</span></span><br><span class="line"><span class="string">"?p                 # 将寄存器 ? 的内容粘贴到光标后</span></span><br><span class="line"><span class="string">"</span>?P                 <span class="comment"># 将寄存器 ? 的内容粘贴到光标前</span></span><br><span class="line">:registers          <span class="comment"># 显示所有寄存器内容</span></span><br><span class="line">:[range]y           <span class="comment"># 复制范围，比如 :20,30y 是复制20到30行，:10y 是复制第十行</span></span><br><span class="line">:[range]d           <span class="comment"># 删除范围，比如 :20,30d 是删除20到30行，:10d 是删除第十行</span></span><br><span class="line">ddp                 <span class="comment"># 交换两行内容：先删除当前行复制到寄存器，并粘贴</span></span><br><span class="line"><span class="string">"_[command]         # 使用[command]删除内容，并且不进行复制（不会污染寄存器）</span></span><br><span class="line"><span class="string">"</span>*[<span class="built_in">command</span>]         <span class="comment"># 使用[command]复制内容到系统剪贴板（需要vim版本有clipboard支持）</span></span><br></pre></td></tr></table></figure>
<p><strong>文本编辑、复制粘贴中的内容可以简单总结为：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">ci<span class="string">'、ci"、ci(、ci[、ci&#123;、ci&lt;            # 分别更改这些配对标点符号中的文本内容</span></span><br><span class="line"><span class="string">di'</span>、di<span class="string">"、di(或dib、di[、di&#123;或diB、di&lt;   # 分别删除这些配对标点符号中的文本内容</span></span><br><span class="line"><span class="string">yi'、yi"</span>、yi(、yi[、yi&#123;、yi&lt;            <span class="comment"># 分别复制这些配对标点符号中的文本内容</span></span><br><span class="line">vi<span class="string">'、vi"、vi(、vi[、vi&#123;、vi&lt;            # 分别选中这些配对标点符号中的文本内容</span></span><br></pre></td></tr></table></figure>
<p>cit、dit、yit、vit，分别操作一对标签之间的内容，编辑html、xml很好用！</p>
<p><strong>另外</strong>，如果把上面的 i 改成 a 可以同时操作配对标点和配对标点内的内容。</p>
<h2 id="移动文本"><a href="#移动文本" class="headerlink" title="移动文本"></a>移动文本</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">:[range]move&#123;address&#125;</span><br></pre></td></tr></table></figure>
<p><strong>参数说明</strong>：</p>
<ul>
<li>[range] 表示要移动的行范围</li>
<li>{address} 表示移动的目标位置，这两个参数都可以缺省</li>
</ul>
<p>例如：<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">:m+1                <span class="comment"># 下移1行</span></span><br><span class="line">:m-2                <span class="comment"># 上移1行</span></span><br><span class="line">:8,10m2             <span class="comment"># 把当前打开文件的第8~10行内容移动到第 2 行下方</span></span><br></pre></td></tr></table></figure></p>
<h2 id="文本对象"><a href="#文本对象" class="headerlink" title="文本对象"></a>文本对象</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line">$                   <span class="comment"># 到行末</span></span><br><span class="line">0                   <span class="comment"># 到行首</span></span><br><span class="line">^                   <span class="comment"># 到行首非空字符</span></span><br><span class="line">iw                  <span class="comment"># 整个单词（不包括分隔符）</span></span><br><span class="line">aw                  <span class="comment"># 整个单词（包括分隔符）</span></span><br><span class="line">iW                  <span class="comment"># 整个 WORD（不包括分隔符）</span></span><br><span class="line">aW                  <span class="comment"># 整个 WORD（包括分隔符）</span></span><br><span class="line">is                  <span class="comment"># 整个句子（不包括分隔符）</span></span><br><span class="line">ib                  <span class="comment"># 小括号内</span></span><br><span class="line">ab                  <span class="comment"># 小括号内（包含小括号本身）</span></span><br><span class="line">iB                  <span class="comment"># 大括号内</span></span><br><span class="line">aB                  <span class="comment"># 大括号内（包含大括号本身）</span></span><br><span class="line">i)                  <span class="comment"># 小括号内</span></span><br><span class="line">a)                  <span class="comment"># 小括号内（包含小括号本身）</span></span><br><span class="line">i]                  <span class="comment"># 中括号内</span></span><br><span class="line">a]                  <span class="comment"># 中括号内（包含中括号本身）</span></span><br><span class="line">i&#125;                  <span class="comment"># 大括号内</span></span><br><span class="line">a&#125;                  <span class="comment"># 大括号内（包含大括号本身）</span></span><br><span class="line">i<span class="string">'                  # 单引号内</span></span><br><span class="line"><span class="string">a'</span>                  <span class="comment"># 单引号内（包含单引号本身）</span></span><br><span class="line">i<span class="string">"                  # 双引号内</span></span><br><span class="line"><span class="string">a"</span>                  <span class="comment"># 双引号内（包含双引号本身）</span></span><br><span class="line">2i)                 <span class="comment"># 往外两层小括号内</span></span><br><span class="line">2a)                 <span class="comment"># 往外两层小括号内（包含小括号本身）</span></span><br><span class="line">2f)                 <span class="comment"># 到第二个小括号处</span></span><br><span class="line">2t)                 <span class="comment"># 到第二个小括号前</span></span><br></pre></td></tr></table></figure>
<h2 id="撤销与恢复"><a href="#撤销与恢复" class="headerlink" title="撤销与恢复"></a>撤销与恢复</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">u                   <span class="comment"># 撤销命令可以组合，例如Nu N是任意整数，表示撤销N步操作，下同</span></span><br><span class="line">U                   <span class="comment"># 撤销整行操作</span></span><br><span class="line">Ctrl+r              <span class="comment"># 撤销上一次 u 命令</span></span><br><span class="line">Ctrl+R              <span class="comment"># 回退前一个命令</span></span><br></pre></td></tr></table></figure>
<h2 id="查找替换"><a href="#查找替换" class="headerlink" title="查找替换"></a>查找替换</h2><p><strong>一般模式下的查找命令：</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">/pattern            <span class="comment"># 从光标处向文件尾搜索 pattern</span></span><br><span class="line">?pattern            <span class="comment"># 从光标处向文件头搜索 pattern</span></span><br><span class="line">n                   <span class="comment"># 向同一方向执行上一次搜索</span></span><br><span class="line">N                   <span class="comment"># 向相反方向执行上一次搜索</span></span><br><span class="line">*                   <span class="comment"># 向前搜索光标下的单词</span></span><br><span class="line"><span class="comment">#                   # 向后搜索光标下的单词</span></span><br><span class="line">f&lt;char&gt;             <span class="comment"># 向后搜索当前行第一个为 &lt;char&gt; 的字符，2fv 可以找到第二个v字符</span></span><br><span class="line">F&lt;char&gt;             <span class="comment"># 向前搜索当前行第一个为 &lt;char&gt; 的字符</span></span><br><span class="line">t&lt;char&gt;             <span class="comment"># 向后搜索当前行第一个为 &lt;char&gt; 的字符前</span></span><br><span class="line">T&lt;char&gt;             <span class="comment"># 向前搜索当前行第一个为 &lt;char&gt; 的字符前</span></span><br><span class="line">;                   <span class="comment"># 重复上次的字符查找命令(f/t命令)</span></span><br><span class="line">,                   <span class="comment"># 反转方向查找上次的字符查找命令(f/t命令)</span></span><br><span class="line">tx                  <span class="comment"># 搜索当前行到指定 字符串 之前</span></span><br><span class="line">fx                  <span class="comment"># 搜索当前行到指定 字符串 之处</span></span><br></pre></td></tr></table></figure>
<p><strong>一般模式下的替换命令：</strong> </p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">:[range]s[ubstitute]/&#123;pattern&#125;/&#123;string&#125;/[flags]</span><br></pre></td></tr></table></figure>
<p>参数说明：</p>
<ul>
<li>pattern：就是要被替换掉的字串，可以用 regexp 來表示</li>
<li>string：將 pattern 由 string 所取代</li>
<li>[range]：有以下一些取值：</li>
</ul>
<table>
<thead>
<tr>
<th>[range]取值</th>
<th>含义</th>
</tr>
</thead>
<tbody>
<tr>
<td>无</td>
<td>默认光标所在行</td>
</tr>
<tr>
<td>.</td>
<td>光标所在当前行</td>
</tr>
<tr>
<td>N</td>
<td>第 N 行</td>
</tr>
<tr>
<td>$</td>
<td>最后一行</td>
</tr>
<tr>
<td>‘a</td>
<td>标记 a 所在的行（之前要用 ma 做过标记）</td>
</tr>
<tr>
<td>$-1</td>
<td>倒数第二行，可以对某一行加减某个数值获得确定的某行</td>
</tr>
<tr>
<td>1,10</td>
<td>第1~10行</td>
</tr>
<tr>
<td>1,$</td>
<td>第一行到最后一行</td>
</tr>
<tr>
<td>1,.</td>
<td>第一行到当前行</td>
</tr>
<tr>
<td>.,$</td>
<td>当前行到最后一行</td>
</tr>
<tr>
<td>‘a,’b</td>
<td>标记 a 所在的行 到 标记 b 所在的行（之前要用 ma、mb 做过标记）</td>
</tr>
<tr>
<td>%</td>
<td>所有行（和 1,$ 等价）</td>
</tr>
<tr>
<td>?str?</td>
<td>从当前位置向上搜索，找到第一个str的行（str可以是正则）</td>
</tr>
<tr>
<td>/str/</td>
<td>从当前位置向下搜索，找到第一个str的行（str可以是正则）</td>
</tr>
</tbody>
</table>
<p>注意，上面的所有用于range的表示方法都可以通过 +、- 操作来设置相对偏移量。</p>
<ul>
<li>[flags]有以下一些取值：</li>
</ul>
<table>
<thead>
<tr>
<th>[flags]取值</th>
<th>含义</th>
</tr>
</thead>
<tbody>
<tr>
<td>g</td>
<td>对指定范围内的所有匹配项（global）进行替换</td>
</tr>
<tr>
<td>c</td>
<td>在替换前请求用户进行确认（confirm）</td>
</tr>
<tr>
<td>e</td>
<td>忽略执行过程中的错误</td>
</tr>
<tr>
<td>i</td>
<td>不区分大小写</td>
</tr>
<tr>
<td>无</td>
<td>只在指定范围内的第一个匹配项进行替换</td>
</tr>
</tbody>
</table>
<p>举例：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">:s/p1/p2/g          <span class="comment"># 将当前行中全替换p1为p2</span></span><br><span class="line">:%s/p1/p2/g         <span class="comment"># 将当前文件中全替换p1为p2</span></span><br><span class="line">:%s/p1/p2/gc        <span class="comment"># 将当前文件中全替换p1为p2，并且每处询问你是否替换</span></span><br><span class="line">:10,20s/p1/p2/g     <span class="comment"># 将第10到20行中所有p1替换为p2</span></span><br><span class="line">:%s/1\\2\/3/123/g   <span class="comment"># 将“1\2/3” 替换为 “123”（特殊字符使用反斜杠标注）</span></span><br><span class="line">:%s/\r//g           <span class="comment"># 删除 DOS 换行符 ^M</span></span><br><span class="line">:%s///gn            <span class="comment"># 统计某个模式的匹配个数</span></span><br><span class="line">:%s/^\s*$\n//g      <span class="comment"># 删除Vim打开文件中所有空白行</span></span><br><span class="line">:g/^\s*$/d          <span class="comment"># 删除Vim打开文件中所有空白行</span></span><br><span class="line">:%s/^M$//g          <span class="comment"># 删除Vim文件中显式的 ^M 符号（操作系统换行符问题）</span></span><br></pre></td></tr></table></figure>
<h2 id="可视模式"><a href="#可视模式" class="headerlink" title="可视模式"></a>可视模式</h2><p><strong>注：Vim 可视模式下可以选择一块编辑区域，然后对选中的文件内容执行插入、删除、替换、改变大小写等操作。！</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">v                   <span class="comment"># 切换到面向字符的可视模式</span></span><br><span class="line">V                   <span class="comment"># 切换到面向行的可视模式</span></span><br><span class="line">Ctrl-V              <span class="comment"># 切换到面向列块的可视模式</span></span><br><span class="line">&gt;                   <span class="comment"># 增加缩进</span></span><br><span class="line">&lt;                   <span class="comment"># 减少缩进</span></span><br><span class="line">d                   <span class="comment"># 删除高亮选中的文字</span></span><br><span class="line">x                   <span class="comment"># 删除高亮选中的文字</span></span><br><span class="line">c                   <span class="comment"># 改写文字，即删除高亮选中的文字并进入插入模式</span></span><br><span class="line">s                   <span class="comment"># 改写文字，即删除高亮选中的文字并进入插入模式</span></span><br><span class="line">y                   <span class="comment"># 拷贝文字</span></span><br><span class="line">~                   <span class="comment"># 转换大小写</span></span><br><span class="line">o                   <span class="comment"># 跳转到标记区的另外一端</span></span><br><span class="line">O                   <span class="comment"># 跳转到标记块的另外一端</span></span><br><span class="line">u                   <span class="comment"># 标记区转换为小写</span></span><br><span class="line">U                   <span class="comment"># 标记区转换为大写</span></span><br><span class="line">gv                  <span class="comment"># 重选上次的高亮选区</span></span><br><span class="line">g Ctrl+G            <span class="comment"># 显示所选择区域的统计信息</span></span><br><span class="line">ggVG                <span class="comment"># 选择全文</span></span><br><span class="line">esc                 <span class="comment"># 按esc键退出可视模式</span></span><br></pre></td></tr></table></figure>
<p>此外： Vim normal 命令可以在命令行模式执行普通模式下的命令，当 normal 命令与 Vim 可视化模式结合时，只需很少的操作就能完成大量重复性工作。</p>
<h2 id="注释命令"><a href="#注释命令" class="headerlink" title="注释命令"></a>注释命令</h2><p><strong>多行注释</strong><br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">Ctrl+v              <span class="comment"># 进入命令行模式，按Ctrl + v进入可视模式，然后按j, 或者k选中多行，把需要注释的行标记起来</span></span><br><span class="line">I                   <span class="comment"># 按大写字母I，再插入注释符，例如#、//</span></span><br><span class="line">esc                 <span class="comment"># 按esc键就会全部注释了</span></span><br></pre></td></tr></table></figure></p>
<p><strong>取消多行注释</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">Ctrl+v              <span class="comment"># 进入命令行模式，按Ctrl + v进入可视模式，按字母l横向选中列的个数，例如#、//（需要选中2列）</span></span><br><span class="line">j 或 k              <span class="comment"># 按字母j，或者k选中注释符号</span></span><br><span class="line">d                   <span class="comment"># 按d键就可全部取消注释</span></span><br></pre></td></tr></table></figure>
<p><strong>复杂注释</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">:起始行号,结束行号s/^/注释符/g（注意冒号）       <span class="comment"># 在指定的行首添加注释</span></span><br><span class="line">:起始行号,结束行号s/^注释符//g（注意冒号）       <span class="comment"># 在指定的行首取消注释</span></span><br><span class="line"></span><br><span class="line">:3,5 s/^/<span class="comment">#/g        # 注释第3-5行</span></span><br><span class="line">:3,5 s/^<span class="comment">#//g        # 解除3-5行的注释</span></span><br><span class="line"></span><br><span class="line">:1,$ s/^/<span class="comment">#/g        # 注释整个文档</span></span><br><span class="line">:1,$ s/^<span class="comment">#//g        # 取消注释整个文档</span></span><br><span class="line"></span><br><span class="line">:%s/^/<span class="comment">#/g           # 注释整个文档，此法更快</span></span><br><span class="line">:%s/^<span class="comment">#//g           # 取消注释整个文档</span></span><br></pre></td></tr></table></figure>
<h2 id="位置跳转"><a href="#位置跳转" class="headerlink" title="位置跳转"></a>位置跳转</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line">Ctrl+O              <span class="comment"># 跳转到上一个位置</span></span><br><span class="line">Ctrl+I              <span class="comment"># 跳转到下一个位置</span></span><br><span class="line">Ctrl+^              <span class="comment"># 跳转到 alternate file (当前窗口的上一个文件）</span></span><br><span class="line">%                   <span class="comment"># 跳转到 &#123;&#125; () [] 的匹配</span></span><br><span class="line">gd                  <span class="comment"># 跳转到局部定义（光标下的单词的定义）</span></span><br><span class="line">gD                  <span class="comment"># 跳转到全局定义（光标下的单词的定义）</span></span><br><span class="line">gf                  <span class="comment"># 打开名称为光标下文件名的文件</span></span><br><span class="line">[[                  <span class="comment"># 跳转到上一个顶层函数（比如C语言以大括号分隔）</span></span><br><span class="line">]]                  <span class="comment"># 跳转到下一个顶层函数（比如C语言以大括号分隔）</span></span><br><span class="line">[m                  <span class="comment"># 跳转到上一个成员函数</span></span><br><span class="line">]m                  <span class="comment"># 跳转到下一个成员函数</span></span><br><span class="line">[&#123;                  <span class="comment"># 跳转到上一处未匹配的 &#123;</span></span><br><span class="line">]&#125;                  <span class="comment"># 跳转到下一处未匹配的 &#125;</span></span><br><span class="line">[(                  <span class="comment"># 跳转到上一处未匹配的 (</span></span><br><span class="line">])                  <span class="comment"># 跳转到下一处未匹配的 )</span></span><br><span class="line">[c                  <span class="comment"># 上一个不同处（diff时）</span></span><br><span class="line">]c                  <span class="comment"># 下一个不同处（diff时）</span></span><br><span class="line">[/                  <span class="comment"># 跳转到 C注释开头</span></span><br><span class="line">]/                  <span class="comment"># 跳转到 C注释结尾</span></span><br><span class="line">``                  <span class="comment"># 回到上次跳转的位置</span></span><br><span class="line"><span class="string">''</span>                  <span class="comment"># 回到上次跳转的位置</span></span><br><span class="line">`.                  <span class="comment"># 回到上次编辑的位置</span></span><br><span class="line"><span class="string">'.                  # 回到上次编辑的位置</span></span><br></pre></td></tr></table></figure>
<h2 id="文件操作"><a href="#文件操作" class="headerlink" title="文件操作"></a>文件操作</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line">:w                  <span class="comment"># 保存文件（会修改文件的时间戳）</span></span><br><span class="line">:w &lt;filename&gt;       <span class="comment"># 按名称保存文件</span></span><br><span class="line">:x                  <span class="comment"># 保存文件并退出（不会修改文件的时间戳）</span></span><br><span class="line">:e &lt;filename&gt;       <span class="comment"># 打开文件并编辑</span></span><br><span class="line">:saveas &lt;filename&gt;  <span class="comment"># 另存为文件</span></span><br><span class="line">:o &lt;filename&gt;       <span class="comment"># 在当前窗口打开另一个文件</span></span><br><span class="line">:r &lt;filename&gt;       <span class="comment"># 读取文件并将内容插入到光标后</span></span><br><span class="line">:r !dir             <span class="comment"># 将 dir 命令的输出捕获并插入到光标后</span></span><br><span class="line">:only               <span class="comment"># 关闭除光标所在的窗口之外的其他窗口</span></span><br><span class="line">:close              <span class="comment"># 关闭光标所在窗口的文件</span></span><br><span class="line">:q                  <span class="comment"># 关闭光标所在的窗口并退出</span></span><br><span class="line">:q!                 <span class="comment"># 强制退出</span></span><br><span class="line">:qa！               <span class="comment"># 关闭所有窗口(不保存)</span></span><br><span class="line">:qall               <span class="comment"># 放弃所有操作并退出</span></span><br><span class="line">:wa                 <span class="comment"># 保存所有文件</span></span><br><span class="line">:wall               <span class="comment"># 保存所有</span></span><br><span class="line">:wqall              <span class="comment"># 保存所有并退出。</span></span><br><span class="line">:<span class="built_in">cd</span> &lt;path&gt;          <span class="comment"># 切换 Vim 当前路径</span></span><br><span class="line">:<span class="built_in">pwd</span>                <span class="comment"># 显示 Vim 当前路径</span></span><br><span class="line">:new                <span class="comment"># 打开一个新的窗口编辑新文件</span></span><br><span class="line">:enew               <span class="comment"># 在当前窗口创建新文件</span></span><br><span class="line">:vnew               <span class="comment"># 在左右切分的新窗口中编辑新文件</span></span><br><span class="line">:tabnew             <span class="comment"># 在新的标签页中编辑新文件</span></span><br><span class="line">:version            <span class="comment"># 查看Vim版本</span></span><br><span class="line">ZZ                  <span class="comment"># 保存文件（如果有改动的话），并关闭窗口</span></span><br><span class="line">ZQ                  <span class="comment"># 不保存文件关闭窗口</span></span><br></pre></td></tr></table></figure>
<h2 id="打开文件"><a href="#打开文件" class="headerlink" title="打开文件"></a>打开文件</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">vim filename        <span class="comment"># 打开或新建文件，并将光标置于第一行首</span></span><br><span class="line">vim + filename      <span class="comment"># 打开文件，并将光标置于最后一行首</span></span><br><span class="line">vim +n filename     <span class="comment"># 打开文件，并将光标置于第 n 行首</span></span><br><span class="line">vim -c cmd file     <span class="comment"># 在打开文件 file 前，先执行指定的Vim命令cmd</span></span><br><span class="line">vim -b file         <span class="comment"># 以二进制模式打开文件，该模式某些特殊字符 (如换行符 ^M) 都可以显示出来</span></span><br><span class="line">vim -d file1 file2  <span class="comment"># 使用Vim同时打开 file1 和 file2 文件并diff两个文件的差异</span></span><br><span class="line">vim -r filename     <span class="comment"># 在上次正用 vim编辑时发生系统崩溃，恢复文件</span></span><br><span class="line">vim -R file         <span class="comment"># 以只读形式打开文件，但是仍然可以使用 :wq! 写入</span></span><br><span class="line">vim -M file         <span class="comment"># 强制性关闭修改功能，无法使用 :wq! 写入 </span></span><br><span class="line">vim -o file1 file2  <span class="comment"># 终端中要打开vim文件时，横向分割显示多个文件</span></span><br><span class="line">vim -O file1 file2  <span class="comment"># 终端中要打开vim文件时，纵向分割显示多个文件</span></span><br><span class="line">vim -x file         <span class="comment"># 以加密方式打开文件</span></span><br><span class="line">vim +/target file   <span class="comment"># 打开 file 并将光标移动到找到的第一个 target 字符串上</span></span><br></pre></td></tr></table></figure>
<h2 id="已打开文件操作"><a href="#已打开文件操作" class="headerlink" title="已打开文件操作"></a>已打开文件操作</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">:ls                 <span class="comment"># 查案缓存列表</span></span><br><span class="line">:bn                 <span class="comment"># 切换到下一个缓存</span></span><br><span class="line">:bp                 <span class="comment"># 切换到上一个缓存</span></span><br><span class="line">:bd                 <span class="comment"># 删除缓存</span></span><br><span class="line">:b 1                <span class="comment"># 切换到1号缓存</span></span><br><span class="line">:b abc              <span class="comment"># 切换到文件名为 abc 开头的缓存</span></span><br><span class="line">:badd &lt;filename&gt;    <span class="comment"># 将文件添加到缓存列表</span></span><br><span class="line">:<span class="built_in">set</span> hidden         <span class="comment"># 设置隐藏模式（未保存的缓存可以被切换走，或者关闭）</span></span><br><span class="line">:<span class="built_in">set</span> nohidden       <span class="comment"># 关闭隐藏模式（未保存的缓存不能被切换走，或者关闭）</span></span><br><span class="line">n Ctrl+^            <span class="comment"># 切换缓存，先输入数字的缓存编号，再按 Ctrl + 6</span></span><br></pre></td></tr></table></figure>
<h2 id="窗口操作"><a href="#窗口操作" class="headerlink" title="窗口操作"></a>窗口操作</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line">:sp &lt;filename&gt;      <span class="comment"># 上下切分窗口并在新窗口打开文件 filename</span></span><br><span class="line">:vs &lt;filename&gt;      <span class="comment"># 左右切分窗口并在新窗口打开文件 filename</span></span><br><span class="line">:split              <span class="comment"># 将当前窗口再复制一个纵向窗口出来，内容同步，游标可以不同</span></span><br><span class="line">:vsplit             <span class="comment"># 将当前窗口再复制一个横向窗口出来，内容同步，游标可以不同</span></span><br><span class="line">Ctrl+W s            <span class="comment"># 上下切分窗口</span></span><br><span class="line">Ctrl+W v            <span class="comment"># 左右切分窗口</span></span><br><span class="line">Ctrl+W w            <span class="comment"># 循环切换到下一个窗口</span></span><br><span class="line">Ctrl+W W            <span class="comment"># 循环切换到上一个窗口</span></span><br><span class="line">Ctrl+W p            <span class="comment"># 跳到上一个访问过的窗口</span></span><br><span class="line">Ctrl+W c            <span class="comment"># 关闭当前窗口</span></span><br><span class="line">Ctrl+W o            <span class="comment"># 关闭其他窗口</span></span><br><span class="line">Ctrl+W h            <span class="comment"># 跳到左边的窗口</span></span><br><span class="line">Ctrl+W j            <span class="comment"># 跳到下边的窗口</span></span><br><span class="line">Ctrl+W k            <span class="comment"># 跳到上边的窗口</span></span><br><span class="line">Ctrl+W l            <span class="comment"># 跳到右边的窗口</span></span><br><span class="line">Ctrl+W +            <span class="comment"># 增加当前窗口的行高，前面可以加数字</span></span><br><span class="line">Ctrl+W -            <span class="comment"># 减少当前窗口的行高，前面可以加数字</span></span><br><span class="line">Ctrl+W &lt;            <span class="comment"># 减少当前窗口的列宽，前面可以加数字</span></span><br><span class="line">Ctrl+W &gt;            <span class="comment"># 增加当前窗口的列宽，前面可以加数字</span></span><br><span class="line">Ctrl+W =            <span class="comment"># 让所有窗口宽高相同</span></span><br><span class="line">Ctrl+W H            <span class="comment"># 将当前窗口移动到最左边</span></span><br><span class="line">Ctrl+W J            <span class="comment"># 将当前窗口移动到最下边</span></span><br><span class="line">Ctrl+W K            <span class="comment"># 将当前窗口移动到最上边</span></span><br><span class="line">Ctrl+W L            <span class="comment"># 将当前窗口移动到最右边</span></span><br><span class="line">Ctrl+W x            <span class="comment"># 交换窗口</span></span><br><span class="line">Ctrl+W f            <span class="comment"># 在新窗口中打开名为光标下文件名的文件</span></span><br><span class="line">Ctrl+W gf           <span class="comment"># 在新标签页中打开名为光标下文件名的文件</span></span><br><span class="line">Ctrl+W R            <span class="comment"># 旋转窗口</span></span><br><span class="line">Ctrl+W T            <span class="comment"># 将当前窗口移到新的标签页中</span></span><br><span class="line">Ctrl+W P            <span class="comment"># 跳转到预览窗口</span></span><br><span class="line">Ctrl+W z            <span class="comment"># 关闭预览窗口</span></span><br><span class="line">Ctrl+W _            <span class="comment"># 纵向最大化当前窗口</span></span><br><span class="line">Ctrl+W |            <span class="comment"># 横向最大化当前窗口</span></span><br></pre></td></tr></table></figure>
<h2 id="标签页"><a href="#标签页" class="headerlink" title="标签页"></a>标签页</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">:tabs               <span class="comment"># 显示所有标签页</span></span><br><span class="line">:tabe &lt;filename&gt;    <span class="comment"># 在新标签页中打开文件 filename</span></span><br><span class="line">:tabn               <span class="comment"># 下一个标签页</span></span><br><span class="line">:tabp               <span class="comment"># 上一个标签页</span></span><br><span class="line">:tabc               <span class="comment"># 关闭当前标签页</span></span><br><span class="line">:tabo               <span class="comment"># 关闭其他标签页</span></span><br><span class="line">:tabn n             <span class="comment"># 切换到第n个标签页，比如 :tabn 3 切换到第三个标签页</span></span><br><span class="line">:tabm n             <span class="comment"># 标签移动</span></span><br><span class="line">:tabfirst           <span class="comment"># 切换到第一个标签页</span></span><br><span class="line">:tablast            <span class="comment"># 切换到最后一个标签页</span></span><br><span class="line">:tab <span class="built_in">help</span>           <span class="comment"># 在标签页打开帮助</span></span><br><span class="line">:tab drop &lt;file&gt;    <span class="comment"># 如果文件已被其他标签页和窗口打开则跳过去，否则新标签打开</span></span><br><span class="line">:tab split          <span class="comment"># 在新的标签页中打开当前窗口里的文件</span></span><br><span class="line">:tab ball           <span class="comment"># 将缓存中所有文件用标签页打开</span></span><br><span class="line">:<span class="built_in">set</span> showtabline=?  <span class="comment"># 设置为 0 就不显示标签页标签，1会按需显示，2会永久显示</span></span><br><span class="line">ngt                 <span class="comment"># 切换到第n个标签页，比如 2gt 将会切换到第二个标签页</span></span><br><span class="line">gt                  <span class="comment"># 下一个标签页</span></span><br><span class="line">gT                  <span class="comment"># 上一个标签页</span></span><br></pre></td></tr></table></figure>
<h2 id="书签"><a href="#书签" class="headerlink" title="书签"></a>书签</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">:marks              <span class="comment"># 显示所有书签</span></span><br><span class="line">ma                  <span class="comment"># 保存当前位置到书签 a ，书签名小写字母为文件内，大写全局</span></span><br><span class="line"><span class="string">'a                  # 跳转到书签 a所在的行</span></span><br><span class="line"><span class="string">`a                  # 跳转到书签 a所在位置</span></span><br><span class="line"><span class="string">`.                  # 跳转到上一次编辑的行</span></span><br><span class="line"><span class="string">'</span>A                  <span class="comment"># 跳转到全文书签 A</span></span><br><span class="line">[<span class="string">'                  # 跳转到上一个书签</span></span><br><span class="line"><span class="string">]'</span>                  <span class="comment"># 跳转到下一个书签</span></span><br><span class="line"><span class="string">'&lt;                  # 跳到上次可视模式选择区域的开始</span></span><br><span class="line"><span class="string">'</span>&gt;                  <span class="comment"># 跳到上次可视模式选择区域的结束</span></span><br></pre></td></tr></table></figure>
<h2 id="帮助信息"><a href="#帮助信息" class="headerlink" title="帮助信息"></a>帮助信息</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">:h tutor            <span class="comment"># 入门文档</span></span><br><span class="line">:h quickref         <span class="comment"># 快速帮助</span></span><br><span class="line">:h index            <span class="comment"># 查询 Vim 所有键盘命令定义</span></span><br><span class="line">:h summary          <span class="comment"># 帮助你更好的使用内置帮助系统</span></span><br><span class="line">:h Ctrl+H           <span class="comment"># 查询普通模式下 Ctrl+H 是干什么的</span></span><br><span class="line">:h i_Ctrl+H         <span class="comment"># 查询插入模式下 Ctrl+H 是干什么的</span></span><br><span class="line">:h i_&lt;Up&gt;           <span class="comment"># 查询插入模式下方向键上是干什么的</span></span><br><span class="line">:h pattern.txt      <span class="comment"># 正则表达式帮助</span></span><br><span class="line">:h <span class="built_in">eval</span>             <span class="comment"># 脚本编写帮助</span></span><br><span class="line">:h <span class="keyword">function</span>-list    <span class="comment"># 查看 VimScript 的函数列表 </span></span><br><span class="line">:h windows.txt      <span class="comment"># 窗口使用帮助</span></span><br><span class="line">:h tabpage.txt      <span class="comment"># 标签页使用帮助</span></span><br><span class="line">:h +timers          <span class="comment"># 显示对 +timers 特性的帮助</span></span><br><span class="line">:h :!               <span class="comment"># 查看如何运行外部命令</span></span><br><span class="line">:h tips             <span class="comment"># 查看 Vim 内置的常用技巧文档</span></span><br><span class="line">:h <span class="built_in">set</span>-termcap      <span class="comment"># 查看如何设置按键扫描码</span></span><br><span class="line">:viusage            <span class="comment"># NORMAL 模式帮助</span></span><br><span class="line">:exusage            <span class="comment"># EX 命令帮助</span></span><br><span class="line">:version            <span class="comment"># 显示当前 Vim 的版本号和特性</span></span><br></pre></td></tr></table></figure>
<h2 id="外部命令"><a href="#外部命令" class="headerlink" title="外部命令"></a>外部命令</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">:!<span class="built_in">command</span>           <span class="comment"># 执行一次性shell命令，如下命令：:!pwd</span></span><br><span class="line">:shell              <span class="comment"># 启动一个交互的 shell 执行多个命令，exit命令退出并返回 Vim</span></span><br><span class="line">:!ls                <span class="comment"># 运行外部命令 ls，并等待返回</span></span><br><span class="line">:r !ls              <span class="comment"># 将外部命令 ls 的输出捕获，并插入到光标后</span></span><br><span class="line">:w !sudo tee %      <span class="comment"># sudo以后保存当前文件</span></span><br><span class="line">:call system(<span class="string">'ls'</span>)  <span class="comment"># 调用 ls 命令，但是不显示返回内容</span></span><br><span class="line">:!start notepad     <span class="comment"># Windows 下启动 notepad，最前面可以加 silent</span></span><br><span class="line">:sil !start cmd     <span class="comment"># Windows 下当前目录打开 cmd</span></span><br><span class="line">:%!prog             <span class="comment"># 运行文字过滤程序，如整理 json格式 :%!python -m json.tool</span></span><br></pre></td></tr></table></figure>
<h2 id="Quickfix-窗口"><a href="#Quickfix-窗口" class="headerlink" title="Quickfix 窗口"></a>Quickfix 窗口</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">:copen              <span class="comment"># 打开 quickfix 窗口（查看编译，grep等信息）</span></span><br><span class="line">:copen 10           <span class="comment"># 打开 quickfix 窗口，并且设置高度为 10</span></span><br><span class="line">:cclose             <span class="comment"># 关闭 quickfix 窗口</span></span><br><span class="line">:cfirst             <span class="comment"># 跳到 quickfix 中第一个错误信息</span></span><br><span class="line">:clast              <span class="comment"># 跳到 quickfix 中最后一条错误信息</span></span><br><span class="line">:cc [nr]            <span class="comment"># 查看错误 [nr]</span></span><br><span class="line">:cnext              <span class="comment"># 跳到 quickfix 中下一个错误信息</span></span><br><span class="line">:cprev              <span class="comment"># 跳到 quickfix 中上一个错误信息</span></span><br></pre></td></tr></table></figure>
<h2 id="拼写检查"><a href="#拼写检查" class="headerlink" title="拼写检查"></a>拼写检查</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">:<span class="built_in">set</span> spell          <span class="comment"># 打开拼写检查</span></span><br><span class="line">:<span class="built_in">set</span> nospell        <span class="comment"># 关闭拼写检查</span></span><br><span class="line">]s                  <span class="comment"># 下一处错误拼写的单词</span></span><br><span class="line">[s                  <span class="comment"># 上一处错误拼写的单词</span></span><br><span class="line">zg                  <span class="comment"># 加入单词到拼写词表中</span></span><br><span class="line">zug                 <span class="comment"># 撤销上一次加入的单词</span></span><br><span class="line">z=                  <span class="comment"># 拼写建议</span></span><br></pre></td></tr></table></figure>
<h2 id="代码折叠"><a href="#代码折叠" class="headerlink" title="代码折叠"></a>代码折叠</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">za                  <span class="comment"># 切换折叠</span></span><br><span class="line">zA                  <span class="comment"># 递归切换折叠</span></span><br><span class="line">zc                  <span class="comment"># 折叠光标下代码</span></span><br><span class="line">zC                  <span class="comment"># 折叠光标下所有代码</span></span><br><span class="line">zd                  <span class="comment"># 删除光标下折叠</span></span><br><span class="line">zD                  <span class="comment"># # 递归删除所有折叠</span></span><br><span class="line">zE                  <span class="comment"># 删除所有折叠</span></span><br><span class="line">zf                  <span class="comment"># 创建代码折叠</span></span><br><span class="line">zF                  <span class="comment"># 指定行数创建折叠</span></span><br><span class="line">zi                  <span class="comment"># 切换折叠</span></span><br><span class="line">zm                  <span class="comment"># 所有代码折叠一层</span></span><br><span class="line">zr                  <span class="comment"># 所有代码打开一层</span></span><br><span class="line">zM                  <span class="comment"># 折叠所有代码，设置 foldlevel=0，设置 foldenable</span></span><br><span class="line">zR                  <span class="comment"># 打开所有代码，设置 foldlevel 为最大值</span></span><br><span class="line">zn                  <span class="comment"># 折叠 none，重置 foldenable 并打开所有代码</span></span><br><span class="line">zN                  <span class="comment"># 折叠 normal，重置 foldenable 并恢复所有折叠</span></span><br><span class="line">zo                  <span class="comment"># 打开一层代码</span></span><br><span class="line">zO                  <span class="comment"># 打开光标下所有代码折叠</span></span><br></pre></td></tr></table></figure>
<h2 id="文档加密解密"><a href="#文档加密解密" class="headerlink" title="文档加密解密"></a>文档加密解密</h2><p><strong>文档加密</strong></p>
<p>加密方式打开文件时，并在屏幕左下角提示输入密码两次才可进行操作，保存文件退出后必须输入正常密码才能正确打开文件，否则会显示乱码。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">vim -x file_name	<span class="comment"># 输入加密密码 -&gt; 确认密码! 注意：不修改内容也要保存。:wq，不然密码设定不会生效。</span></span><br><span class="line">:X 			<span class="comment"># 命令行模式下，输入加密密码 -&gt; 确认密码! 注意：不修改内容也要保存。:wq，不然密码设定不会生效。</span></span><br><span class="line">:<span class="built_in">set</span> key=密码		<span class="comment"># 命令行模式下，输入加密密码 -&gt; 确认密码! 注意：不修改内容也要保存。:wq，不然密码设定不会生效。</span></span><br></pre></td></tr></table></figure>
<p><strong>文档解密</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">:X 			<span class="comment"># 命令行模式下，提示输入密码，不输入而是按 Enter。注意：不修改内容也要保存。:wq，不然解密设定不会生效。</span></span><br><span class="line">:<span class="built_in">set</span> key=		<span class="comment"># 命令行模式下，设置key的密码为空。注意：不修改内容也要保存。:wq，不然密码设定不会生效。</span></span><br></pre></td></tr></table></figure>
<h2 id="宏录制"><a href="#宏录制" class="headerlink" title="宏录制"></a>宏录制</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">qa                  <span class="comment"># 开始录制名字为 a 的宏</span></span><br><span class="line">q                   <span class="comment"># 结束录制宏</span></span><br><span class="line">@a                  <span class="comment"># 播放名字为 a 的宏</span></span><br><span class="line">@@                  <span class="comment"># 播放上一个宏</span></span><br><span class="line">@:                  <span class="comment"># 重复上一个ex命令（即冒号命令）</span></span><br></pre></td></tr></table></figure>
<h2 id="其他命令"><a href="#其他命令" class="headerlink" title="其他命令"></a>其他命令</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><span class="line">Ctrl+X Ctrl+E       <span class="comment"># 插入模式下向上滚屏</span></span><br><span class="line">Ctrl+X Ctrl+Y       <span class="comment"># 插入模式下向下滚屏</span></span><br><span class="line">Ctrl+G              <span class="comment"># 显示正在编辑的文件名，以及大小和位置信息</span></span><br><span class="line">g Ctrl+G            <span class="comment"># 显示文件的：大小，字符数，单词数和行数，可视模式下也可用</span></span><br><span class="line">ga                  <span class="comment"># 显示光标下字符的 ascii 码或者 unicode 编码</span></span><br><span class="line">g8                  <span class="comment"># 显示光标下字符的 utf-8 编码字节序</span></span><br><span class="line">gi                  <span class="comment"># 回到上次进入插入的地方，并切换到插入模式</span></span><br><span class="line">K                   <span class="comment"># 查询光标下单词的帮助</span></span><br><span class="line">Ctrl+PgUp           <span class="comment"># 上个标签页，GVim OK，部分终端软件需设置对应键盘码</span></span><br><span class="line">Ctrl+PgDown         <span class="comment"># 下个标签页，GVim OK，部分终端软件需设置对应键盘码</span></span><br><span class="line">Ctrl+R Ctrl+W       <span class="comment"># 命令模式下插入光标下单词</span></span><br><span class="line">Ctrl+Insert         <span class="comment"># 复制到系统剪贴板（GVIM）</span></span><br><span class="line">Shift+Insert        <span class="comment"># 粘贴系统剪贴板的内容（GVIM）</span></span><br><span class="line">:<span class="built_in">set</span> ff=unix        <span class="comment"># 设置换行为 unix</span></span><br><span class="line">:<span class="built_in">set</span> ff=dos         <span class="comment"># 设置换行为 dos</span></span><br><span class="line">:<span class="built_in">set</span> ff?            <span class="comment"># 查看换行设置</span></span><br><span class="line">:<span class="built_in">set</span> nohl           <span class="comment"># 清除搜索高亮</span></span><br><span class="line">:<span class="built_in">set</span> termcap        <span class="comment"># 查看会从终端接收什么以及会发送给终端什么命令</span></span><br><span class="line">:<span class="built_in">set</span> guicursor=     <span class="comment"># 解决 SecureCRT/PenguiNet 中 NeoVim 局部奇怪字符问题</span></span><br><span class="line">:<span class="built_in">set</span> t_RS= t_SH=    <span class="comment"># 解决 SecureCRT/PenguiNet 中 Vim8.0 终端功能奇怪字符</span></span><br><span class="line">:<span class="built_in">set</span> fo+=a          <span class="comment"># 开启文本段的实时自动格式化</span></span><br><span class="line">:earlier 15m        <span class="comment"># 回退到15分钟前的文件内容</span></span><br><span class="line">:map                <span class="comment"># 来查看当前 Vim 配置的 map 快捷键</span></span><br><span class="line">:inoremap           <span class="comment"># 来查看当前 Vim 配置的 inoremap 快捷键</span></span><br><span class="line">:nnoremap           <span class="comment"># 来查看当前 Vim 配置的 nnoremap 快捷键</span></span><br><span class="line">:.!date             <span class="comment"># 在当前窗口插入时间</span></span><br><span class="line">:%!xxd              <span class="comment"># 开始二进制编辑</span></span><br><span class="line">:%!xxd -r           <span class="comment"># 保存二进制编辑</span></span><br><span class="line">:r !curl -sL &#123;URL&#125;  <span class="comment"># 读取 url 内容添加到光标后</span></span><br><span class="line">:g/^\s*$/d          <span class="comment"># 删除空行</span></span><br><span class="line">:g/green/d          <span class="comment"># 删除所有包含 green 的行</span></span><br><span class="line">:v/green/d          <span class="comment"># 删除所有不包含 green 的行</span></span><br><span class="line">:g/gladiolli/<span class="comment">#      # 搜索单词打印结果，并在结果前加上行号</span></span><br><span class="line">:g/ab.*<span class="built_in">cd</span>.*efg/<span class="comment">#    # 搜索包含 ab,cd 和 efg 的行，打印结果以及行号</span></span><br><span class="line">:v/./,/./-j         <span class="comment"># 压缩空行</span></span><br><span class="line">:Man bash           <span class="comment"># 在 Vim 中查看 man，先调用 :runtime! ftplugin/man.vim 激活</span></span><br><span class="line">/fred\|joe          <span class="comment"># 搜索 fred 或者 joe</span></span><br><span class="line">/\&lt;\d\d\d\d\&gt;       <span class="comment"># 精确搜索四个数字</span></span><br><span class="line">/^\n\&#123;3&#125;            <span class="comment"># 搜索连续三个空行</span></span><br></pre></td></tr></table></figure>
<h2 id="查看命令历史"><a href="#查看命令历史" class="headerlink" title="查看命令历史"></a>查看命令历史</h2><p>命令行模式下：<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">:<span class="built_in">history</span>                <span class="comment"># 查看所有命令行模式下输入的命令历史</span></span><br><span class="line">:<span class="built_in">history</span> search或 / 或？ <span class="comment"># 查看搜索历史</span></span><br></pre></td></tr></table></figure></p>
<p>普通模式下：<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">q/                  <span class="comment"># 查看使用/输入的搜索历史</span></span><br><span class="line">q?                  <span class="comment"># 查看使用？输入的搜索历史</span></span><br><span class="line">q:                  <span class="comment"># 查看命令行历史</span></span><br></pre></td></tr></table></figure></p>
<h2 id="寄存器"><a href="#寄存器" class="headerlink" title="寄存器"></a>寄存器</h2><p><strong>查看寄存器值</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">:reg                   <span class="comment"># 查看所有寄存器值</span></span><br><span class="line">:reg <span class="string">"&#123;register_name&#125;  # 查看指定寄存器值</span></span><br></pre></td></tr></table></figure>
<p><strong>调取寄存器值</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">"&#123;register_name&#125;        # 普通模式下调取寄存器值</span></span><br><span class="line"><span class="string">:Ctrl+r "</span>寄存器名称      <span class="comment"># 命令模式下（输入 Ctrl+r 后Vim会自动打出"寄存器引用符号）</span></span><br><span class="line">Ctrl+r 寄存器名称        <span class="comment"># 插入模式下（无需输入寄存器引用符号"）</span></span><br></pre></td></tr></table></figure>
<p><strong>Vim寄存器分类</strong></p>
<table>
<thead>
<tr>
<th>名称</th>
<th>引用方式</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>无名寄存器</td>
<td>“”</td>
<td>默认寄存器，所有的复制和修改操作（x、s、d、c、y）都会将该数据复制到无名寄存器</td>
</tr>
<tr>
<td>字母寄存器</td>
<td>“a - “z 或 “A - “Z</td>
<td>{register_name}只能是一位的26个英文字母，从a-z，A-Z寄存器内容将会合并到对应小写字母内容后边</td>
</tr>
<tr>
<td>复制专用寄存器</td>
<td>“0（数字0）</td>
<td>仅当使用复制操作(y)时，该数据将会同时被复制到无名寄存器和复制专用寄存器</td>
</tr>
<tr>
<td>逐级临时缓存寄存器</td>
<td>“1 - “9</td>
<td>所有不带范围（‘(’，‘)’，‘{’，‘}’）、操作涉及1行以上的删除修改操作（x、s、d、c）的数据都会复制到逐级临时缓存寄存器，并在新的数据加入时，逐级先后推移。1的数据复制到2，2的复制到3，最后的9寄存器内容将会被删除</td>
</tr>
<tr>
<td>黑洞寄存器</td>
<td>“_</td>
<td>几乎所有的操作涉及的数据都会被复制到寄存器，如果想让操作的数据不经过寄存器，可以指定黑洞寄存器，数据到该寄存器就会消失掉，不能显示，也不存在</td>
</tr>
<tr>
<td>系统剪切板</td>
<td>“+ 或”*</td>
<td>与Vim外部的GUI交互数据时，需要使用专用的系统剪切板</td>
</tr>
<tr>
<td>表达式寄存器</td>
<td>“=</td>
<td>所有寄存器里最特殊的一个，用于计算表达式。输入完该寄存器应用后，会在命令行里提示“=”，按需输入表达式，结果将会显示到光标处</td>
</tr>
<tr>
<td>其他寄存器</td>
<td></td>
</tr>
</tbody>
</table>
<h2 id="Vim设置"><a href="#Vim设置" class="headerlink" title="Vim设置"></a>Vim设置</h2><p>编辑Vim配置文件：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">:edit <span class="variable">$MYVIMRC</span>      <span class="comment"># 在Vim的命令模式下使用该命令打开 vim 配置文件</span></span><br><span class="line">:<span class="built_in">source</span> <span class="variable">$MYVIMRC</span>    <span class="comment"># Vim 配置文件的改动后，使用该命令为vim配置文件加载新的配置选项，如果vimrc文件恰好是当前活动的缓冲区，则可把此命令简化为:so %。</span></span><br></pre></td></tr></table></figure>
<p>Vim配置说明：</p>
<p><strong>注：Vim配置可以在命令模式下单个设置，只在当前窗口生效！</strong><br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line">syntax              <span class="comment"># 列出已经定义的语法项</span></span><br><span class="line">syntax clear        <span class="comment"># 清除已定义的语法规则</span></span><br><span class="line">syntax on           <span class="comment"># 允许语法高亮</span></span><br><span class="line">syntax off          <span class="comment"># 禁止语法高亮</span></span><br><span class="line"><span class="built_in">set</span> <span class="built_in">history</span>=200     <span class="comment"># 记录 200 条历史命令</span></span><br><span class="line"><span class="built_in">set</span> bs=?            <span class="comment">#  设置BS键模式，现代编辑器为 :set bs=eol,start,indent</span></span><br><span class="line"><span class="built_in">set</span> sw=4            <span class="comment"># 设置缩进宽度为 4</span></span><br><span class="line"><span class="built_in">set</span> ts=4            <span class="comment"># 设置制表符宽度为 4</span></span><br><span class="line"><span class="built_in">set</span> noet            <span class="comment"># 设置不展开 tab 成空格</span></span><br><span class="line"><span class="built_in">set</span> et              <span class="comment"># 设置展开 tab 成空格</span></span><br><span class="line"><span class="built_in">set</span> winaltkeys=no   <span class="comment"># 设置 GVim 下正常捕获 ALT 键</span></span><br><span class="line"><span class="built_in">set</span> nowrap          <span class="comment"># 关闭自动换行</span></span><br><span class="line"><span class="built_in">set</span> ttimeout        <span class="comment"># 允许终端按键检测超时（终端下功能键为一串ESC开头的扫描码）</span></span><br><span class="line"><span class="built_in">set</span> ttm=100         <span class="comment"># 设置终端按键检测超时为100毫秒</span></span><br><span class="line"><span class="built_in">set</span> term=?          <span class="comment"># 设置终端类型，比如常见的 xterm</span></span><br><span class="line"><span class="built_in">set</span> ignorecase      <span class="comment"># 设置搜索是否忽略大小写</span></span><br><span class="line"><span class="built_in">set</span> smartcase       <span class="comment"># 智能大小写，默认忽略大小写，除非搜索内容里包含大写字母</span></span><br><span class="line"><span class="built_in">set</span> list            <span class="comment"># 设置显示制表符和换行符</span></span><br><span class="line"><span class="built_in">set</span> nu              <span class="comment"># 设置显示行号，禁止显示行号可以用 :set nonu</span></span><br><span class="line"><span class="built_in">set</span> number          <span class="comment"># 设置显示行号，禁止显示行号可以用 :set nonumber</span></span><br><span class="line"><span class="built_in">set</span> relativenumber  <span class="comment"># 设置显示相对行号（其他行与当前行的距离）</span></span><br><span class="line"><span class="built_in">set</span> paste           <span class="comment"># 进入粘贴模式（粘贴时禁用缩进等影响格式的东西）</span></span><br><span class="line"><span class="built_in">set</span> nopaste         <span class="comment"># 结束粘贴模式</span></span><br><span class="line"><span class="built_in">set</span> spell           <span class="comment"># 允许拼写检查</span></span><br><span class="line"><span class="built_in">set</span> hlsearch        <span class="comment"># 设置高亮查找</span></span><br><span class="line"><span class="built_in">set</span> ruler           <span class="comment"># 总是显示光标位置</span></span><br><span class="line"><span class="built_in">set</span> nocompatible    <span class="comment"># 设置不兼容原始 vi 模式（必须设置在最开头）</span></span><br><span class="line"><span class="built_in">set</span> incsearch       <span class="comment"># 查找输入时动态增量显示查找结果</span></span><br><span class="line"><span class="built_in">set</span> insertmode      <span class="comment"># Vim 始终处于插入模式下，使用 Ctrl+o 临时执行命令</span></span><br><span class="line"><span class="built_in">set</span> all             <span class="comment"># 列出所有选项设置情况</span></span><br></pre></td></tr></table></figure></p>
<h2 id="Vim插件"><a href="#Vim插件" class="headerlink" title="Vim插件"></a>Vim插件</h2><h3 id="插件-vim-commentary"><a href="#插件-vim-commentary" class="headerlink" title="插件 - vim-commentary"></a>插件 - <a href="https://github.com/tpope/vim-commentary" target="_blank" rel="noopener">vim-commentary</a></h3><p><strong>vim-commentary</strong>：批量注释工具, 可以注释多行和去除多行注释。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">gcc                 <span class="comment"># 注释当前行</span></span><br><span class="line">gc&#123;motion&#125;          <span class="comment"># 注释 &#123;motion&#125; 所标注的区域，比如 gcap 注释整段</span></span><br><span class="line">gci&#123;                <span class="comment"># 注释大括号内的内容</span></span><br><span class="line">gc                  <span class="comment"># 在 Visual Mode 下面按 gc 注释选中区域</span></span><br><span class="line">:7,17Commentary     <span class="comment"># 注释 7 到 17 行</span></span><br></pre></td></tr></table></figure>
<h3 id="插件-nerdtree"><a href="#插件-nerdtree" class="headerlink" title="插件 - nerdtree"></a>插件 - <a href="https://github.com/preservim/nerdtree" target="_blank" rel="noopener">nerdtree</a></h3><p><strong>nerdtree</strong>：该插件用于列出当前路径的目录树。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line">?                   <span class="comment"># 快速帮助文档</span></span><br><span class="line">o                   <span class="comment"># 打开一个目录或者打开文件，创建的是buffer，也可以用来打开书签</span></span><br><span class="line">go                  <span class="comment"># 打开一个文件，但是光标仍然留在NERDTree，创建的是buffer</span></span><br><span class="line">t                   <span class="comment"># 打开一个文件，创建的是Tab，对书签同样生效</span></span><br><span class="line">T                   <span class="comment"># 打开一个文件，但是光标仍然留在NERDTree，创建的是Tab，对书签同样生效</span></span><br><span class="line">i                   <span class="comment"># 水平分割创建文件的窗口，创建的是buffer</span></span><br><span class="line">gi                  <span class="comment"># 水平分割创建文件的窗口，但是光标仍然留在NERDTree</span></span><br><span class="line">s                   <span class="comment"># 垂直分割创建文件的窗口，创建的是buffer</span></span><br><span class="line">gs                  <span class="comment"># 和gi，go类似</span></span><br><span class="line">x                   <span class="comment"># 收起当前打开的目录</span></span><br><span class="line">X                   <span class="comment"># 收起所有打开的目录</span></span><br><span class="line">e                   <span class="comment"># 以文件管理的方式打开选中的目录</span></span><br><span class="line">D                   <span class="comment"># 删除书签</span></span><br><span class="line">P                   <span class="comment"># 大写，跳转到当前根路径</span></span><br><span class="line">p                   <span class="comment"># 小写，跳转到光标所在的上一级路径</span></span><br><span class="line">K                   <span class="comment"># 跳转到第一个子路径</span></span><br><span class="line">J                   <span class="comment"># 跳转到最后一个子路径</span></span><br><span class="line">Ctrl+j和Ctrl+k      <span class="comment"># 在同级目录和文件间移动，忽略子目录和子文件</span></span><br><span class="line">C                   <span class="comment"># 将根路径设置为光标所在的目录</span></span><br><span class="line">u                   <span class="comment"># 设置上级目录为根路径</span></span><br><span class="line">U                   <span class="comment"># 设置上级目录为跟路径，但是维持原来目录打开的状态</span></span><br><span class="line">r                   <span class="comment"># 刷新光标所在的目录</span></span><br><span class="line">R                   <span class="comment"># 刷新当前根路径</span></span><br><span class="line">I                   <span class="comment"># 显示或者不显示隐藏文件</span></span><br><span class="line">f                   <span class="comment"># 打开和关闭文件过滤器</span></span><br><span class="line">q                   <span class="comment"># 关闭NERDTree</span></span><br><span class="line">A                   <span class="comment"># 全屏显示NERDTree，或者关闭全屏</span></span><br></pre></td></tr></table></figure>
<h3 id="插件-asyncrun-vim"><a href="#插件-asyncrun-vim" class="headerlink" title="插件 - asyncrun.vim"></a>插件 - <a href="https://github.com/skywind3000/asyncrun.vim" target="_blank" rel="noopener">asyncrun.vim</a></h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">:AsyncRun ls        <span class="comment"># 异步运行命令 ls 结果输出到 quickfix 使用 :copen 查看</span></span><br><span class="line">:AsyncRun -raw ls   <span class="comment"># 异步运行命令 ls 结果不匹配 errorformat</span></span><br></pre></td></tr></table></figure>
<h2 id="Vim模式"><a href="#Vim模式" class="headerlink" title="Vim模式"></a>Vim模式</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">普通模式            <span class="comment"># 按 Esc 或 Ctrl+[ 进入，左下角显示文件名或为空</span></span><br><span class="line">插入模式            <span class="comment"># 按i进入，左下角显示 --INSERT--</span></span><br><span class="line">可视模式            <span class="comment"># 按v进入，左下角显示 --VISUAL--</span></span><br><span class="line">替换模式            <span class="comment"># 按r或R开始，左下角显示 --REPLACE--</span></span><br><span class="line">命令行模式          <span class="comment"># 按 : 或者 / 或者 ? 开始</span></span><br></pre></td></tr></table></figure>
<h2 id="网络资源"><a href="#网络资源" class="headerlink" title="网络资源"></a>网络资源</h2><ul>
<li>最新版本            <a href="https://github.com/vim/vim" target="_blank" rel="noopener">https://github.com/vim/vim</a>   </li>
<li>Windows 最新版      <a href="https://github.com/vim/vim-win32-installer/releases" target="_blank" rel="noopener">https://github.com/vim/vim-win32-installer/releases</a></li>
<li>插件浏览            <a href="http://vimawesome.com" target="_blank" rel="noopener">http://vimawesome.com</a></li>
<li>正确设置ALT/BS键    <a href="http://www.skywind.me/blog/archives/2021" target="_blank" rel="noopener">http://www.skywind.me/blog/archives/2021</a></li>
<li>视频教程            <a href="http://vimcasts.org/" target="_blank" rel="noopener">http://vimcasts.org/</a></li>
<li>中文帮助            <a href="http://vimcdoc.sourceforge.net/doc/help.html" target="_blank" rel="noopener">http://vimcdoc.sourceforge.net/doc/help.html</a></li>
<li>中文版入门到精通    <a href="https://github.com/wsdjeg/vim-galore-zh_cn" target="_blank" rel="noopener">https://github.com/wsdjeg/vim-galore-zh_cn</a></li>
<li>五分钟脚本入门      <a href="http://www.skywind.me/blog/archives/2193" target="_blank" rel="noopener">http://www.skywind.me/blog/archives/2193</a></li>
<li>脚本精通            <a href="http://learnvimscriptthehardway.stevelosh.com/" target="_blank" rel="noopener">http://learnvimscriptthehardway.stevelosh.com/</a></li>
<li>十六年使用经验      <a href="http://zzapper.co.uk/vimtips.html" target="_blank" rel="noopener">http://zzapper.co.uk/vimtips.html</a></li>
<li>配色方案            <a href="http://vimcolors.com/" target="_blank" rel="noopener">http://vimcolors.com/</a></li>
</ul>
<h2 id="TIPS"><a href="#TIPS" class="headerlink" title="TIPS"></a>TIPS</h2><ul>
<li>永远不要用 Ctrl+C 代替 <esc> 完全不同的含义，容易错误中断运行的后台脚本</esc></li>
<li>很多人使用 Ctrl+[ 代替 <esc>，左手小指 Ctrl，右手小指 [ 熟练后很方便</esc></li>
<li>某些终端中使用 Vim 8 内嵌终端如看到奇怪字符，使用 :set t_RS= t_SH= 解决</li>
<li>某些终端中使用 NeoVim 如看到奇怪字符，使用 :set guicursor= 解决</li>
<li>多使用 ciw, ci[, ci”, ci( 以及 diw, di[, di”, di( 命令来快速改写/删除文本</li>
<li>在行内左右移动光标时，多使用w b e或W B E，而不是h l或方向键，这样会快很多</li>
<li>Shift 相当于移动加速键， w b e 移动光标很慢，但是 W B E 走的很快</li>
<li>自己要善于总结新技巧，比如移动到行首非空字符时用 0w 命令比 ^ 命令更容易输入</li>
<li>在空白行使用 dip 命令可以删除所有临近的空白行，viw 可以选择连续空白</li>
<li>缩进时使用 &gt;8j &gt;} <ap>ap =i} == 会方便很多</ap></li>
<li>插入模式下，当你发现一个单词写错了，应该多用 Ctrl+W 这比 <backspace> 快</backspace></li>
<li>y d c 命令可以很好结合 f t 和 /X 比如 dt) 和 y/end<cr></cr></li>
<li>c d x 命令会自动填充寄存器 “1 到 “9 , y 命令会自动填充 “0 寄存器</li>
<li>用 v 命令选择文本时，可以用 o 掉头选择，有时很有用</li>
<li>写文章时，可以写一段代码块，然后选中后执行 :!python 代码块就会被替换成结果</li>
<li>搜索后经常使用 :nohl 来消除高亮，使用很频繁，可以 map 到 <backspace> 上</backspace></li>
<li>搜索时可以用 Ctrl+R Ctrl+W 插入光标下的单词，命令模式也能这么用</li>
<li>映射按键时，应该默认使用 noremap ，只有特别需要的时候使用 map</li>
<li>当你觉得做某事很低效时，你应该停下来，然后思考正确的高效方式来完成</li>
<li>用 y 复制文本后，命令模式中 Ctrl+R 然后按双引号 0 可以插入之前复制内容</li>
<li>Windows 下的 GVim 可以设置 set rop=type:directx,renmode:5 增强显示</li>
</ul>
<h2 id="书籍"><a href="#书籍" class="headerlink" title="书籍"></a>书籍</h2><p><a href="https://pan.baidu.com/s/1tocUYzByGDzKxEqYTFH7ug" target="_blank" rel="noopener">Vim实用技巧</a></p>
<h2 id="Vim键盘图"><a href="#Vim键盘图" class="headerlink" title="Vim键盘图"></a>Vim键盘图</h2><p><img src="/uploads/vim.png" alt="vim.png"></p>
<h2 id="参考"><a href="#参考" class="headerlink" title="参考"></a>参考</h2><ul>
<li><a href="https://github.com/skywind3000/awesome-cheatsheets/blob/master/editors/vim.txt" target="_blank" rel="noopener">https://github.com/skywind3000/awesome-cheatsheets/blob/master/editors/vim.txt</a></li>
<li><a href="https://github.com/groenewege/vimrc/blob/master/vim_cheat_sheet.txt" target="_blank" rel="noopener">https://github.com/groenewege/vimrc/blob/master/vim_cheat_sheet.txt</a></li>
<li><a href="http://blog.g-design.net/post/4789778607/vim-cheat-sheet" target="_blank" rel="noopener">http://blog.g-design.net/post/4789778607/vim-cheat-sheet</a></li>
<li><a href="http://www.keyxl.com/aaa8263/290/VIM-keyboard-shortcuts.htm" target="_blank" rel="noopener">http://www.keyxl.com/aaa8263/290/VIM-keyboard-shortcuts.htm</a></li>
<li><a href="http://jmcpherson.org/editing.html" target="_blank" rel="noopener">http://jmcpherson.org/editing.html</a></li>
<li><a href="http://www.fprintf.net/vimCheatSheet.html" target="_blank" rel="noopener">http://www.fprintf.net/vimCheatSheet.html</a></li>
<li><a href="http://www.ouyaoxiazai.com/article/24/654.html" target="_blank" rel="noopener">http://www.ouyaoxiazai.com/article/24/654.html</a></li>
<li><a href="http://bbs.it-home.org/thread-80794-1-1.html" target="_blank" rel="noopener">http://bbs.it-home.org/thread-80794-1-1.html</a></li>
<li><a href="http://www.lpfrx.com/wp-content/uploads/2008/09/vi.jpg" target="_blank" rel="noopener">http://www.lpfrx.com/wp-content/uploads/2008/09/vi.jpg</a></li>
<li><a href="http://michael.peopleofhonoronly.com/vim/" target="_blank" rel="noopener">http://michael.peopleofhonoronly.com/vim/</a></li>
<li><a href="https://github.com/hobbestigrou/vimtips-fortune/blob/master/fortunes/vimtips" target="_blank" rel="noopener">https://github.com/hobbestigrou/vimtips-fortune/blob/master/fortunes/vimtips</a></li>
<li><a href="https://github.com/glts/vim-cottidie/blob/master/autoload/cottidie/tips" target="_blank" rel="noopener">https://github.com/glts/vim-cottidie/blob/master/autoload/cottidie/tips</a></li>
</ul>
<hr>

      
    </div>

    

    
    
    

    

    
      
    
    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div>您的支持是对我最大的鼓励</div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById(&quot;QR&quot;); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>打赏</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="/images/wechatpay.jpg" alt="chloneda 微信支付">
        <p>微信支付</p>
      </div>
    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="/images/alipay.jpg" alt="chloneda 支付宝">
        <p>支付宝</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    
      <div>
        



  



<ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者： </strong>chloneda</li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    
    <a href="https://chloneda.github.io/blog/vim-cheatsheet/" title="Vim命令速查表">https://chloneda.github.io/blog/vim-cheatsheet/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" rel="noopener" target="_blank"><i class="fa fa-fw fa-creative-commons"></i>BY-NC-SA</a> 许可协议。转载请注明出处！</li>
</ul>

      </div>
    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Vim/" rel="tag"># Vim</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/blog/spring-ud/" rel="next" title="Spring文件上传下载">
                <i class="fa fa-chevron-left"></i> Spring文件上传下载
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/blog/git-config/" rel="prev" title="git config全局和本地配置">
                git config全局和本地配置 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>


  </div>


          </div>
          

        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>
  
  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="/images/chloneda.jpeg" alt="chloneda">
            
              <p class="site-author-name" itemprop="name">chloneda</p>
              <p class="site-description motion-element" itemprop="description">Less is more</p>
          </div>

          
            <nav class="site-state motion-element">
              
                <div class="site-state-item site-state-posts">
                
                  <a href="/archives/">
                
                    <span class="site-state-item-count">31</span>
                    <span class="site-state-item-name">日志</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-categories">
                  <a href="/categories/index.html">
                    
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">16</span>
                    <span class="site-state-item-name">分类</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-tags">
                  <a href="/tags/index.html">
                    
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">16</span>
                    <span class="site-state-item-name">标签</span>
                  </a>
                </div>
              
            </nav>
          

          
            <div class="feed-link motion-element">
              <a href="/rss2.html" rel="alternate">
                <i class="fa fa-rss"></i>
                RSS
              </a>
            </div>
          

          
            <div class="links-of-author motion-element">
              
                <span class="links-of-author-item">
                  
                  
                    
                  
                  
                    
                  
                  <a href="https://github.com/chloneda" title="GitHub &rarr; https://github.com/chloneda" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i>GitHub</a>
                </span>
              
                <span class="links-of-author-item">
                  
                  
                    
                  
                  
                    
                  
                  <a href="https://twitter.com/chloneda" title="Twitter &rarr; https://twitter.com/chloneda" rel="noopener" target="_blank"><i class="fa fa-fw fa-twitter"></i>Twitter</a>
                </span>
              
                <span class="links-of-author-item">
                  
                  
                    
                  
                  
                    
                  
                  <a href="mailto:chloneda@gmail.com" title="E-Mail &rarr; mailto:chloneda@gmail.com" rel="noopener" target="_blank"><i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                </span>
              
                <span class="links-of-author-item">
                  
                  
                    
                  
                  
                    
                  
                  <a href="https://weibo.com/chloneda" title="Weibo &rarr; https://weibo.com/chloneda" rel="noopener" target="_blank"><i class="fa fa-fw fa-weibo"></i>Weibo</a>
                </span>
              
                <span class="links-of-author-item">
                  
                  
                    
                  
                  
                    
                  
                  <a href="http://www.zhihu.com/people/chl_vip" title="知乎 &rarr; http://www.zhihu.com/people/chl_vip" rel="noopener" target="_blank"><i class="fa fa-fw fa-globe"></i>知乎</a>
                </span>
              
                <span class="links-of-author-item">
                  
                  
                    
                  
                  
                    
                  
                  <a href="https://www.cnblogs.com/chloneda" title="博客园 &rarr; https://www.cnblogs.com/chloneda" rel="noopener" target="_blank"><i class="fa fa-fw fa-globe"></i>博客园</a>
                </span>
              
            </div>
          

          

          
          


	  <div id="music163player">
		<iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width="330" height="86" src="//music.163.com/outchain/player?type=2&id=5239700&auto=0&height=66"></iframe>
	  </div>

          
            
          
          

        </div>
      </div>

      
      <!--noindex-->
        <div class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
            
            
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#Vim命令速查表"><span class="nav-number">1.</span> <span class="nav-text">Vim命令速查表</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#光标移动"><span class="nav-number">1.1.</span> <span class="nav-text">光标移动</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#插入模式"><span class="nav-number">1.2.</span> <span class="nav-text">插入模式</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#插入模式的命令"><span class="nav-number">1.3.</span> <span class="nav-text">插入模式的命令</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#自动补全"><span class="nav-number">1.4.</span> <span class="nav-text">自动补全</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#文本编辑"><span class="nav-number">1.5.</span> <span class="nav-text">文本编辑</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#复制粘贴"><span class="nav-number">1.6.</span> <span class="nav-text">复制粘贴</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#移动文本"><span class="nav-number">1.7.</span> <span class="nav-text">移动文本</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#文本对象"><span class="nav-number">1.8.</span> <span class="nav-text">文本对象</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#撤销与恢复"><span class="nav-number">1.9.</span> <span class="nav-text">撤销与恢复</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#查找替换"><span class="nav-number">1.10.</span> <span class="nav-text">查找替换</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#可视模式"><span class="nav-number">1.11.</span> <span class="nav-text">可视模式</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#注释命令"><span class="nav-number">1.12.</span> <span class="nav-text">注释命令</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#位置跳转"><span class="nav-number">1.13.</span> <span class="nav-text">位置跳转</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#文件操作"><span class="nav-number">1.14.</span> <span class="nav-text">文件操作</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#打开文件"><span class="nav-number">1.15.</span> <span class="nav-text">打开文件</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#已打开文件操作"><span class="nav-number">1.16.</span> <span class="nav-text">已打开文件操作</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#窗口操作"><span class="nav-number">1.17.</span> <span class="nav-text">窗口操作</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#标签页"><span class="nav-number">1.18.</span> <span class="nav-text">标签页</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#书签"><span class="nav-number">1.19.</span> <span class="nav-text">书签</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#帮助信息"><span class="nav-number">1.20.</span> <span class="nav-text">帮助信息</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#外部命令"><span class="nav-number">1.21.</span> <span class="nav-text">外部命令</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Quickfix-窗口"><span class="nav-number">1.22.</span> <span class="nav-text">Quickfix 窗口</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#拼写检查"><span class="nav-number">1.23.</span> <span class="nav-text">拼写检查</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#代码折叠"><span class="nav-number">1.24.</span> <span class="nav-text">代码折叠</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#文档加密解密"><span class="nav-number">1.25.</span> <span class="nav-text">文档加密解密</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#宏录制"><span class="nav-number">1.26.</span> <span class="nav-text">宏录制</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#其他命令"><span class="nav-number">1.27.</span> <span class="nav-text">其他命令</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#查看命令历史"><span class="nav-number">1.28.</span> <span class="nav-text">查看命令历史</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#寄存器"><span class="nav-number">1.29.</span> <span class="nav-text">寄存器</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Vim设置"><span class="nav-number">1.30.</span> <span class="nav-text">Vim设置</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Vim插件"><span class="nav-number">1.31.</span> <span class="nav-text">Vim插件</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#插件-vim-commentary"><span class="nav-number">1.31.1.</span> <span class="nav-text">插件 - vim-commentary</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#插件-nerdtree"><span class="nav-number">1.31.2.</span> <span class="nav-text">插件 - nerdtree</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#插件-asyncrun-vim"><span class="nav-number">1.31.3.</span> <span class="nav-text">插件 - asyncrun.vim</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Vim模式"><span class="nav-number">1.32.</span> <span class="nav-text">Vim模式</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#网络资源"><span class="nav-number">1.33.</span> <span class="nav-text">网络资源</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#TIPS"><span class="nav-number">1.34.</span> <span class="nav-text">TIPS</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#书籍"><span class="nav-number">1.35.</span> <span class="nav-text">书籍</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Vim键盘图"><span class="nav-number">1.36.</span> <span class="nav-text">Vim键盘图</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#参考"><span class="nav-number">1.37.</span> <span class="nav-text">参考</span></a></li></ol></li></ol></div>
            

          </div>
        </div>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; 2018 – <span itemprop="copyrightYear">2020</span>
  <span class="with-love" id="animate">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">chloneda</span>

  

  
</div>


  <div class="powered-by">由 <a href="https://hexo.io" class="theme-link" rel="noopener" target="_blank">Hexo</a> 强力驱动 v3.8.0</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 – <a href="https://theme-next.org" class="theme-link" rel="noopener" target="_blank">NexT.Mist</a> v7.0.0</div>




        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="post-meta-item-icon">
      <i class="fa fa-user"></i>
    </span>
    <span class="site-uv" title="总访客量">
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
    </span>
  

  
    <span class="post-meta-divider">|</span>
  

  
    <span class="post-meta-item-icon">
      <i class="fa fa-eye"></i>
    </span>
    <span class="site-pv" title="总访问量">
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
    </span>
  
</div>









        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
          <span id="scrollpercent"><span>0</span>%</span>
        
      </div>
    

    

    

    
  </div>

  

<script>
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>


























  
  <script src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>


  


  <script src="/js/src/utils.js?v=7.0.0"></script>

  <script src="/js/src/motion.js?v=7.0.0"></script>



  
  


  <script src="/js/src/schemes/muse.js?v=7.0.0"></script>




  
  <script src="/js/src/scrollspy.js?v=7.0.0"></script>
<script src="/js/src/post-details.js?v=7.0.0"></script>



  


  <script src="/js/src/bootstrap.js?v=7.0.0"></script>



  



  
  <script>
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url).replace(/\/{2,}/g, '/');
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x"></i></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x"></i></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  
  <script src="https://www.gstatic.com/firebasejs/4.6.0/firebase.js"></script>
  <script src="https://www.gstatic.com/firebasejs/4.6.0/firebase-firestore.js"></script>
  
  <script>
    (function () {

      firebase.initializeApp({
        apiKey: '',
        projectId: ''
      })

      function getCount(doc, increaseCount) {
        //increaseCount will be false when not in article page

        return doc.get().then(function (d) {
          var count
          if (!d.exists) { //has no data, initialize count
            if (increaseCount) {
              doc.set({
                count: 1
              })
              count = 1
            }
            else {
              count = 0
            }
          }
          else { //has data
            count = d.data().count
            if (increaseCount) {
              if (!(window.localStorage && window.localStorage.getItem(title))) { //if first view this article
                doc.set({ //increase count
                  count: count + 1
                })
                count++
              }
            }
          }
          if (window.localStorage && increaseCount) { //mark as visited
            localStorage.setItem(title, true)
          }

          return count
        })
      }

      function appendCountTo(el) {
        return function (count) {
          $(el).append(
            $('<span>').addClass('post-visitors-count').append(
              $('<span>').addClass('post-meta-divider').text('|')
            ).append(
              $('<span>').addClass('post-meta-item-icon').append(
                $('<i>').addClass('fa fa-users')
              )
              ).append($('<span>').text('阅读次数 ' + count))
          )
        }
      }

      var db = firebase.firestore()
      var articles = db.collection('articles')

      //https://hexo.io/docs/variables.html
      var isPost = 'Vim命令速查表'.length > 0
      var isArchive = '' === 'true'
      var isCategory = ''.length > 0
      var isTag = ''.length > 0

      if (isPost) { //is article page
        var title = 'Vim命令速查表'
        var doc = articles.doc(title)

        getCount(doc, true).then(appendCountTo($('.post-meta')))
      }
      else if (!isArchive && !isCategory && !isTag) { //is index page
        var titles = [] //array to titles

        var postsstr = '' //if you have a better way to get titles of posts, please change it
        eval(postsstr)

        var promises = titles.map(function (title) {
          return articles.doc(title)
        }).map(function (doc) {
          return getCount(doc)
        })
        Promise.all(promises).then(function (counts) {
          var metas = $('.post-meta')
          counts.forEach(function (val, idx) {
            appendCountTo(metas[idx])(val)
          })
        })
      }
    })()
  </script>


  

  

  
  <script>
    (function(){
      var bp = document.createElement('script');
      var curProtocol = window.location.protocol.split(':')[0];
      bp.src = (curProtocol === 'https') ? 'https://zz.bdstatic.com/linksubmit/push.js' : 'http://push.zhanzhang.baidu.com/push.js';
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(bp, s);
    })();
  </script>


  

  

  

  

  

  

  

  
  <style>
    .copy-btn {
      display: inline-block;
      padding: 6px 12px;
      font-size: 13px;
      font-weight: 700;
      line-height: 20px;
      color: #333;
      white-space: nowrap;
      vertical-align: middle;
      cursor: pointer;
      background-color: #eee;
      background-image: linear-gradient(#fcfcfc, #eee);
      border: 1px solid #d5d5d5;
      border-radius: 3px;
      user-select: none;
      outline: 0;
    }

    .highlight-wrap .copy-btn {
      transition: opacity .3s ease-in-out;
      opacity: 0;
      padding: 2px 6px;
      position: absolute;
      right: 4px;
      top: 8px;
    }

    .highlight-wrap:hover .copy-btn,
    .highlight-wrap .copy-btn:focus {
      opacity: 1
    }

    .highlight-wrap {
      position: relative;
    }
  </style>
  <script>
    $('.highlight').each(function(i, e) {
      var $wrap = $('<div>').addClass('highlight-wrap');
      $(e).after($wrap);
      $wrap.append($('<button>').addClass('copy-btn').append('复制').on('click', function(e) {
        var code = $(this).parent().find('.code').find('.line').map(function(i, e) {
          return $(e).text();
        }).toArray().join('\n');
        var ta = document.createElement('textarea');
        var range = document.createRange(); //For Chrome
        var sel = window.getSelection(); //For Chrome
        var yPosition = window.pageYOffset || document.documentElement.scrollTop;
        ta.style.top = yPosition + 'px'; //Prevent page scroll
        ta.style.position = 'absolute';
        ta.style.opacity = '0';
        ta.value = code;
        ta.textContent = code; //For FireFox
        ta.contentEditable = true;
        ta.readOnly = false;
        document.body.appendChild(ta);
        range.selectNode(ta);
        sel.removeAllRanges();
        sel.addRange(range);
        ta.setSelectionRange(0, code.length);
        var result = document.execCommand('copy');
        
        ta.blur(); //For iOS
        $(this).blur();
      })).on('mouseleave', function(e) {
        var $b = $(this).find('.copy-btn');
        setTimeout(function() {
          $b.text('复制');
        }, 300);
      }).append(e);
    })
  </script>


</body>
</html>
